<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh" lang="zh">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<meta name="Keywords" content="Zope, Plone, bfg, 开源社区">
<meta content="这里是Zope开源web应用服务器和Plone开源内容管理系统的中文技术社区。" name="description">
<!-- Plone ECMAScripts --><style type="text/css">
            .tabber{display:none}
        </style>
<style type="text/css">
            <!-- @import url(http://everydo.com/themes/czug.org/css/ploneStyles6234.css); -->
        </style>
<link rel="alternate stylesheet" type="text/css" media="screen" href="http://everydo.com/themes/czug.org/css/ploneStyles0053.css" title="Small Text">
<link rel="alternate stylesheet" type="text/css" media="screen" href="http://everydo.com/themes/czug.org/css/ploneStyles2144.css" title="Large Text">
<style type="text/css" media="all">
            <!-- @import url(http://everydo.com/themes/czug.org/css/ploneStyles8099.css); -->
        </style>
<link rel="stylesheet" href="http://everydo.com/themes/czug.org/css/navtree.css" type="text/css">
<script type="text/javascript" src="http://everydo.com/resources/thecmsface/js/sarissa.js">
        </script><script type="text/javascript" src="http://everydo.com/resources/thecmsface/js/base2-dom-fp.js">
        </script><script type="text/javascript" src="http://everydo.com/resources/thecmsface/js/kukit.js">
        </script><script type="text/javascript" src="http://everydo.com/resources/thecmsface/js/zopen.js">
        </script><link type="text/css" rel="kinetic-stylesheet" href="http://czug.org/static/navtree.kss" media="all">
<!-- Internet Explorer CSS Fixes --><!--[if IE]>
            <style type="text/css" media="all">
                @import url(IEFixes.css);
            </style>
        <![endif]--><link rel="shortcut icon" type="image/x-icon" href="http://everydo.com/themes/czug.org/img/favicon.ico">
<link rel="home" href="http://czug.org" title="Front page">
<link rel="search" href="http://everydo.com/themes/czug.org/search_form" title="Search this site">
<link rel="author" href="http://everydo.com/themes/czug.org/author/panjy" title="Author information">
<link rel="contents" href="http://everydo.com/sitemap" title="Site Map">
<!-- Disable IE6 image toolbar --><meta http-equiv="imagetoolbar" content="no">
<title>第十五章 树形控件 - 中国Zope/Plone用户组</title>
</head>
<body class="section-index_html" dir="ltr">
        <div id="visual-portal-wrapper">
            <div id="portal-top">
                <div id="portal-header">
                    <p class="hiddenStructure">
                        <a accesskey="2" href="http://everydo.com/themes/czug.org/index.html?notheme#documentContent">
                            Skip to content.
                        </a>
                        |
                        <a accesskey="6" href="http://everydo.com/themes/czug.org/index.html?notheme#portlet-navigation-tree">
                            Skip to navigation
                        </a>
                    </p>
                    <h1 id="portal-logo">
                        <a href="http://czug.org" accesskey="1">
                            中国Zope/Plone用户组
                        </a>
                    </h1>
                    <div id="portal-skinswitcher">
                    </div>
                    <h5 class="hiddenStructure">
                        Sections
                    </h5>
                    <ul id="portal-globalnav">
<li id="首页" class="plain">
                        <a href="/">首页</a>
                      </li>
<li id="Zope" class="plain">
                        <a href="/zope">Zope</a>
                      </li>
<li id="Plone" class="plain">
                        <a href="/plone">Plone</a>
                      </li>
<li id="Python" class="selected">
                        <a href="/python">Python</a>
                      </li>
<li id="社区项目" class="plain">
                        <a href="/projects">社区项目</a>
                      </li>
<li id="博客群" class="plain">
                        <a href="/blog/">博客群</a>
                      </li>
<li id="关于" class="plain">
                        <a href="/about">关于</a>
                      </li>
</ul>
</div>
                <div id="portal-personaltools-wrapper">
                    <h5 class="hiddenStructure">
                        Personal tools
                    </h5>
                </div>
                <!-- <div id="portal-breadcrumbs">
                <span id="breadcrumbs-you-are-here">You
                are here:</span>
                <a href="http://czug.org">Home</a>
                </div>
                -->
            </div>
            <div class="visualClear" id="clear-space-before-wrapper-table">
                <!-- -->
            </div>
            <table id="portal-columns"><tbody><tr id="portal-tr">
<td id="portal-column-one">
            <div class="visualPadding"> <div class="document">

<div id="leftcolumn" class="edoBox">
  <b class="xtop edoxtop">
    <b class="xb1"></b>
    <b class="xb2"></b>
    <b class="xb3"></b>
    <b class="xb4"></b>
 </b>
 <b class="itemxtop edoitemxtop">
    <b class="itemxb1"></b>
    <b class="itemxb2"></b>
    <b class="itemxb3"></b>
    <b class="itemxb4"></b>
 </b>
 <dl class="portlet portlet-navigation-tree">
<dt class="portletHeader">
        <a class="title" href="http://www.czug.org/python/wxpythoninaction/">《活学活用wxPython》</a>
    </dt>
    <dd class="portletItem">
        <ul class="portletNavigationTree navTreeLevel0">
<li class="navTreeItem visualNoMarker node notloaded collapsed" kssattr:nodeurl="http://www.czug.org/python/wxpythoninaction/pr01.htm">
    <div class="visualIcon contenttype-folder">
        <a border="0" class="visualIconPadding 
        " name="pr01.htm" href="http://www.czug.org/python/wxpythoninaction/pr01.htm" onfocus="this.blur()">
        
        
        前言
            </a>
    </div>
    
</li>

<li class="navTreeItem visualNoMarker node notloaded collapsed" kssattr:nodeurl="http://www.czug.org/python/wxpythoninaction/pr02.htm">
    <div class="visualIcon contenttype-folder">
        <a border="0" class="visualIconPadding 
        " name="pr02.htm" href="http://www.czug.org/python/wxpythoninaction/pr02.htm" onfocus="this.blur()">
        
        
        关于本书
            </a>
    </div>
    
</li>

<li class="navTreeItem visualNoMarker node notloaded collapsed" kssattr:nodeurl="http://www.czug.org/python/wxpythoninaction/ch01.htm">
    <div class="visualIcon contenttype-folder">
        <a border="0" class="visualIconPadding 
        " name="ch01.htm" href="http://www.czug.org/python/wxpythoninaction/ch01.htm" onfocus="this.blur()">
        
        
        第一章 欢迎使用wxPython
            </a>
    </div>
    
</li>

<li class="navTreeItem visualNoMarker node notloaded collapsed" kssattr:nodeurl="http://www.czug.org/python/wxpythoninaction/ch02.htm">
    <div class="visualIcon contenttype-folder">
        <a border="0" class="visualIconPadding 
        " name="ch02.htm" href="http://www.czug.org/python/wxpythoninaction/ch02.htm" onfocus="this.blur()">
        
        
        第二章 给wxPython程序一个坚实的基础
            </a>
    </div>
    
</li>

<li class="navTreeItem visualNoMarker node notloaded collapsed" kssattr:nodeurl="http://www.czug.org/python/wxpythoninaction/ch03.htm">
    <div class="visualIcon contenttype-folder">
        <a border="0" class="visualIconPadding 
        " name="ch03.htm" href="http://www.czug.org/python/wxpythoninaction/ch03.htm" onfocus="this.blur()">
        
        
        第三章 在事件驱动环境中开发
            </a>
    </div>
    
</li>

<li class="navTreeItem visualNoMarker node notloaded collapsed" kssattr:nodeurl="http://www.czug.org/python/wxpythoninaction/ch04.htm">
    <div class="visualIcon contenttype-folder">
        <a border="0" class="visualIconPadding 
        " name="ch04.htm" href="http://www.czug.org/python/wxpythoninaction/ch04.htm" onfocus="this.blur()">
        
        
        第四章 用PyCrust使得wxPython更易处理
            </a>
    </div>
    
</li>

<li class="navTreeItem visualNoMarker node notloaded collapsed" kssattr:nodeurl="http://www.czug.org/python/wxpythoninaction/ch05.htm">
    <div class="visualIcon contenttype-folder">
        <a border="0" class="visualIconPadding 
        " name="ch05.htm" href="http://www.czug.org/python/wxpythoninaction/ch05.htm" onfocus="this.blur()">
        
        
        第五章 绘制蓝图
            </a>
    </div>
    
</li>

<li class="navTreeItem visualNoMarker node notloaded collapsed" kssattr:nodeurl="http://www.czug.org/python/wxpythoninaction/ch06.htm">
    <div class="visualIcon contenttype-folder">
        <a border="0" class="visualIconPadding 
        " name="ch06.htm" href="http://www.czug.org/python/wxpythoninaction/ch06.htm" onfocus="this.blur()">
        
        
        第六章 使用wxPython基本构件
            </a>
    </div>
    
</li>

<li class="navTreeItem visualNoMarker node notloaded collapsed" kssattr:nodeurl="http://www.czug.org/python/wxpythoninaction/ch07.htm">
    <div class="visualIcon contenttype-folder">
        <a border="0" class="visualIconPadding 
        " name="ch07.htm" href="http://www.czug.org/python/wxpythoninaction/ch07.htm" onfocus="this.blur()">
        
        
        第七章 使用基础控件
            </a>
    </div>
    
</li>

<li class="navTreeItem visualNoMarker node notloaded collapsed" kssattr:nodeurl="http://www.czug.org/python/wxpythoninaction/ch08.htm">
    <div class="visualIcon contenttype-folder">
        <a border="0" class="visualIconPadding 
        " name="ch08.htm" href="http://www.czug.org/python/wxpythoninaction/ch08.htm" onfocus="this.blur()">
        
        
        第八章 将构件放入窗体中
            </a>
    </div>
    
</li>

<li class="navTreeItem visualNoMarker node notloaded collapsed" kssattr:nodeurl="http://www.czug.org/python/wxpythoninaction/ch09.htm">
    <div class="visualIcon contenttype-folder">
        <a border="0" class="visualIconPadding 
        " name="ch09.htm" href="http://www.czug.org/python/wxpythoninaction/ch09.htm" onfocus="this.blur()">
        
        
        第九章 通过对话框让用户选择
            </a>
    </div>
    
</li>

<li class="navTreeItem visualNoMarker node notloaded collapsed" kssattr:nodeurl="http://www.czug.org/python/wxpythoninaction/ch10.htm">
    <div class="visualIcon contenttype-folder">
        <a border="0" class="visualIconPadding 
        " name="ch10.htm" href="http://www.czug.org/python/wxpythoninaction/ch10.htm" onfocus="this.blur()">
        
        
        第十章 创建和使用wxPython菜单
            </a>
    </div>
    
</li>

<li class="navTreeItem visualNoMarker node notloaded collapsed" kssattr:nodeurl="http://www.czug.org/python/wxpythoninaction/ch11.htm">
    <div class="visualIcon contenttype-folder">
        <a border="0" class="visualIconPadding 
        " name="ch11.htm" href="http://www.czug.org/python/wxpythoninaction/ch11.htm" onfocus="this.blur()">
        
        
        第十一章 使用sizer放置构件
            </a>
    </div>
    
</li>

<li class="navTreeItem visualNoMarker node notloaded collapsed" kssattr:nodeurl="http://www.czug.org/python/wxpythoninaction/ch12.htm">
    <div class="visualIcon contenttype-folder">
        <a border="0" class="visualIconPadding 
        " name="ch12.htm" href="http://www.czug.org/python/wxpythoninaction/ch12.htm" onfocus="this.blur()">
        
        
        第十二章 操作基本图像
            </a>
    </div>
    
</li>

<li class="navTreeItem visualNoMarker node notloaded collapsed" kssattr:nodeurl="http://www.czug.org/python/wxpythoninaction/ch13.htm">
    <div class="visualIcon contenttype-folder">
        <a border="0" class="visualIconPadding 
        " name="ch13.htm" href="http://www.czug.org/python/wxpythoninaction/ch13.htm" onfocus="this.blur()">
        
        
        第十三章 建造列表控件并管理列表项
            </a>
    </div>
    
</li>

<li class="navTreeItem visualNoMarker node notloaded collapsed" kssattr:nodeurl="http://www.czug.org/python/wxpythoninaction/ch14.htm">
    <div class="visualIcon contenttype-folder">
        <a border="0" class="visualIconPadding 
        " name="ch14.htm" href="http://www.czug.org/python/wxpythoninaction/ch14.htm" onfocus="this.blur()">
        
        
        第十四章 网格控件
            </a>
    </div>
    
</li>

<li class="navTreeItem visualNoMarker node selected notloaded collapsed" kssattr:nodeurl="http://www.czug.org/python/wxpythoninaction/ch15.htm">
    <div class="visualIcon contenttype-folder">
        <a border="0" class="visualIconPadding 
        navTreeCurrentItem" name="ch15.htm" href="http://www.czug.org/python/wxpythoninaction/ch15.htm" onfocus="this.blur()">
        
        
        第十五章 树形控件
            </a>
    </div>
    
</li>

<li class="navTreeItem visualNoMarker node notloaded collapsed" kssattr:nodeurl="http://www.czug.org/python/wxpythoninaction/ch16.htm">
    <div class="visualIcon contenttype-folder">
        <a border="0" class="visualIconPadding 
        " name="ch16.htm" href="http://www.czug.org/python/wxpythoninaction/ch16.htm" onfocus="this.blur()">
        
        
        第十六章 在应用程序中加入HTML
            </a>
    </div>
    
</li>

<li class="navTreeItem visualNoMarker node notloaded collapsed" kssattr:nodeurl="http://www.czug.org/python/wxpythoninaction/ch17.htm">
    <div class="visualIcon contenttype-folder">
        <a border="0" class="visualIconPadding 
        " name="ch17.htm" href="http://www.czug.org/python/wxpythoninaction/ch17.htm" onfocus="this.blur()">
        
        
        第十七章 wxPython的打印构架
            </a>
    </div>
    
</li>

<li class="navTreeItem visualNoMarker node notloaded collapsed" kssattr:nodeurl="http://www.czug.org/python/wxpythoninaction/ch18.htm">
    <div class="visualIcon contenttype-folder">
        <a border="0" class="visualIconPadding 
        " name="ch18.htm" href="http://www.czug.org/python/wxpythoninaction/ch18.htm" onfocus="this.blur()">
        
        
        第十八章 使用wxPython的其他功能
            </a>
    </div>
    
</li>

            <!--p class="navTreeItem visualNoMarker" 
               tal:repeat="node items" 
               tal:replace="structure node">
            </p-->
        </ul>
</dd>
    <dd class="portletFooter">
        <div><!-- --></div>
    </dd>
  </dl>
<b class="xbottom"><b class="xb4"></b><b class="xb3"></b><b class="xb2"></b><b class="xb1"></b></b>
</div>
</div>
 </div> </td>
<td id="portal-column-content">
                            <div id="content" class="documentContent">
<h1>第十五章 树形控件</h1>
<div lang="en" id="content" dir="ltr">
<span id="top" class="anchor"></span>
<span id="line-1" class="anchor"></span><p class="line867">
</p>
<h1 id="head-6013a9883a38346769ebc83e3cbcb1dfdeec481f">1. 树形控件(tree control)</h1>
<span id="line-2" class="anchor"></span><p class="line874">本章内容 <span id="line-3" class="anchor"></span><span id="line-4" class="anchor"></span></p>
<ul>
<li>创建树形控件并添加项目 <span id="line-5" class="anchor"></span>
</li>
<li>使用样式来设计树形控件 <span id="line-6" class="anchor"></span>
</li>
<li>在程序中访问树形控件 <span id="line-7" class="anchor"></span>
</li>
<li>处理树形控件中的选择 <span id="line-8" class="anchor"></span>
</li>
<li>控制项目的可见性 <span id="line-9" class="anchor"></span>
</li>
</ul>
<p class="line862">树形控件是用于显示复杂数据的控件。这里，树形控件被设计用来通过分级层来显示数据，你可以看到每 块数据都有父子方面的东西。一个标准的例子就是文件树，其中的目录中有子目录或文件，从而形成了文 件的一个嵌套的层次。另一个例子是<tt>HTML</tt>或<tt>XML</tt>文档的文档对象模型(<tt>DOM)</tt>树。和列表与网格控件一样，树
形控件也提供了在项目显示方面的灵活性，并允许你就地编辑树形控件中的项目。在这一章中，我们将给 你展示如何编辑树形控件中的项目及如何响应用户事件。 <span id="line-10" class="anchor"></span><span id="line-11" class="anchor"></span></p>
<p class="line867">
</p>
<h2 id="head-2efa548a4b481e7908a568d50b778af61855a831">1.1. 创建树形控件并添加项目</h2>
<span id="line-12" class="anchor"></span><p class="line862">树形控件是类<tt>wx.TreeCtrl</tt>的实例。图15.1显示了一个树形控件的样例。 <span id="line-13" class="anchor"></span><span id="line-14" class="anchor"></span></p>
<p class="line867"><strong>图15.1</strong> <span id="line-15" class="anchor"></span><span id="line-16" class="anchor"></span></p>
<p class="line867"><img title="attachment:w15.1.gif" src="/moin/WxPythonInAction/ChapterFifteen?action=AttachFile&amp;do=get&amp;target=w15.1.gif" class="attachment"><span id="line-17" class="anchor"></span><span id="line-18" class="anchor"></span></p>
<p class="line862">例15.1是产生图15.1的代码。这个例子中的机制我们将在后面的部分讨论。注意其中的树形控件中的数据 是来自于一个名为<tt>data.py</tt>外部文件的。 <span id="line-19" class="anchor"></span><span id="line-20" class="anchor"></span></p>
<p class="line867"><strong>例15.1</strong>  <strong>树形控件示例</strong> <span id="line-21" class="anchor"></span><span id="line-22" class="anchor"></span></p>
<p class="line867"><span id="line-23" class="anchor"></span><span id="line-24" class="anchor"></span><span id="line-25" class="anchor"></span><span id="line-26" class="anchor"></span><span id="line-27" class="anchor"></span><span id="line-28" class="anchor"></span><span id="line-29" class="anchor"></span><span id="line-30" class="anchor"></span><span id="line-31" class="anchor"></span><span id="line-32" class="anchor"></span><span id="line-33" class="anchor"></span><span id="line-34" class="anchor"></span><span id="line-35" class="anchor"></span><span id="line-36" class="anchor"></span><span id="line-37" class="anchor"></span><span id="line-38" class="anchor"></span><span id="line-39" class="anchor"></span><span id="line-40" class="anchor"></span><span id="line-41" class="anchor"></span><span id="line-42" class="anchor"></span><span id="line-43" class="anchor"></span><span id="line-44" class="anchor"></span><span id="line-45" class="anchor"></span><span id="line-46" class="anchor"></span><span id="line-47" class="anchor"></span><span id="line-48" class="anchor"></span><span id="line-49" class="anchor"></span><span id="line-50" class="anchor"></span><span id="line-51" class="anchor"></span><span id="line-52" class="anchor"></span><span id="line-53" class="anchor"></span><span id="line-54" class="anchor"></span><span id="line-55" class="anchor"></span><span id="line-56" class="anchor"></span><span id="line-57" class="anchor"></span><span id="line-58" class="anchor"></span><span id="line-59" class="anchor"></span><span id="line-60" class="anchor"></span><span id="line-61" class="anchor"></span><span id="line-62" class="anchor"></span><span id="line-63" class="anchor"></span><span id="line-64" class="anchor"></span><span id="line-65" class="anchor"></span><span id="line-66" class="anchor"></span><span id="line-67" class="anchor"></span><span id="line-68" class="anchor"></span><span id="line-69" class="anchor"></span><span id="line-70" class="anchor"></span><span id="line-71" class="anchor"></span><span id="line-72" class="anchor"></span><span id="line-73" class="anchor"></span></p>
<div lang="en" dir="ltr" class="codearea">
<script type="text/javascript">
function isnumbered(obj) {
return obj.childNodes.length && obj.firstChild.childNodes.length && obj.firstChild.firstChild.className == 'LineNumber';
}
function nformat(num,chrs,add) {
var nlen = Math.max(0,chrs-(''+num).length), res = '';
while (nlen>0) { res += ' '; nlen-- }
return res+num+add;
}
function addnumber(did, nstart, nstep) {
var c = document.getElementById(did), l = c.firstChild, n = 1;
if (!isnumbered(c))
if (typeof nstart == 'undefined') nstart = 1;
if (typeof nstep  == 'undefined') nstep = 1;
n = nstart;
while (l != null) {
if (l.tagName == 'SPAN') {
var s = document.createElement('SPAN');
s.className = 'LineNumber'
s.appendChild(document.createTextNode(nformat(n,4,' ')));
n += nstep;
if (l.childNodes.length)
l.insertBefore(s, l.firstChild)
else
l.appendChild(s)
}
l = l.nextSibling;
}
return false;
}
function remnumber(did) {
var c = document.getElementById(did), l = c.firstChild;
if (isnumbered(c))
while (l != null) {
if (l.tagName == 'SPAN' && l.firstChild.className == 'LineNumber') l.removeChild(l.firstChild);
l = l.nextSibling;
}
return false;
}
function togglenumber(did, nstart, nstep) {
var c = document.getElementById(did);
if (isnumbered(c)) {
remnumber(did);
} else {
addnumber(did,nstart,nstep);
}
return false;
}
</script><script type="text/javascript">
document.write('<a href="#" onclick="return togglenumber(\'CA-875af13a0ad3d8f0ba6f9057d89361b95192b89f_000\', 1, 1);" \
class="codenumbers">切换行号显示<\/a>');
</script><a class="codenumbers" onclick="return togglenumber('CA-875af13a0ad3d8f0ba6f9057d89361b95192b89f_000', 1, 1);" href="#">切换行号显示</a>
<pre lang="en" id="CA-875af13a0ad3d8f0ba6f9057d89361b95192b89f_000" dir="ltr"><span class="line"><span class="LineNumber">   1 </span><span class="ResWord">import</span> <span class="ID">wx</span></span>
<span class="line"><span class="LineNumber">   2 </span><span class="ResWord">import</span> <span class="ID">data</span></span>
<span class="line"><span class="LineNumber">   3 </span><span class="ResWord">class</span> <span class="ID">TestFrame</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">Frame</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">   4 </span>    <span class="ResWord">def</span> <span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">   5 </span>        <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Frame</span><span class="Operator">.</span><span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">None</span><span class="Operator">,</span> <span class="ID">title</span><span class="Operator">=</span><span class="String">"simple tree"</span><span class="Operator">,</span> <span class="ID">size</span><span class="Operator">=</span><span class="Operator">(</span><span class="Number">400</span><span class="Operator">,</span><span class="Number">500</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">   6 </span>        <span class="Comment"># Create the tree</span></span>
<span class="line"><span class="LineNumber">   7 </span><span class="Comment"></span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">tree</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">TreeCtrl</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">   8 </span>        <span class="Comment"># Add a root node</span></span>
<span class="line"><span class="LineNumber">   9 </span><span class="Comment"></span>        <span class="ID">root</span> <span class="Operator">=</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">tree</span><span class="Operator">.</span><span class="ID">AddRoot</span><span class="Operator">(</span><span class="String">"wx.Object"</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  10 </span>        <span class="Comment"># Add nodes from our data set</span></span>
<span class="line"><span class="LineNumber">  11 </span><span class="Comment"></span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">AddTreeNodes</span><span class="Operator">(</span><span class="ID">root</span><span class="Operator">,</span> <span class="ID">data</span><span class="Operator">.</span><span class="ID">tree</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  12 </span>        <span class="Comment"># Bind some interesting events</span></span>
<span class="line"><span class="LineNumber">  13 </span><span class="Comment"></span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Bind</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_TREE_ITEM_EXPANDED</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">OnItemExpanded</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">tree</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  14 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Bind</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_TREE_ITEM_COLLAPSED</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">OnItemCollapsed</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">tree</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  15 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Bind</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_TREE_SEL_CHANGED</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">OnSelChanged</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">tree</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  16 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Bind</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_TREE_ITEM_ACTIVATED</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">OnActivated</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">tree</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  17 </span>        <span class="Comment"># Expand the first level</span></span>
<span class="line"><span class="LineNumber">  18 </span><span class="Comment"></span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">tree</span><span class="Operator">.</span><span class="ID">Expand</span><span class="Operator">(</span><span class="ID">root</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  19 </span>    <span class="ResWord">def</span> <span class="ID">AddTreeNodes</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">parentItem</span><span class="Operator">,</span> <span class="ID">items</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  20 </span>        <span class="String">"""</span></span>
<span class="line"><span class="LineNumber">  21 </span><span class="String">        Recursively traverses the data structure, adding tree nodes to</span></span>
<span class="line"><span class="LineNumber">  22 </span><span class="String">        match it.</span></span>
<span class="line"><span class="LineNumber">  23 </span><span class="String">        """</span></span>
<span class="line"><span class="LineNumber">  24 </span>        <span class="ResWord">for</span> <span class="ID">item</span> <span class="ResWord">in</span> <span class="ID">items</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  25 </span>            <span class="ResWord">if</span> <span class="ID">type</span><span class="Operator">(</span><span class="ID">item</span><span class="Operator">)</span> <span class="Operator">==</span> <span class="ID">str</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  26 </span>                <span class="ID">self</span><span class="Operator">.</span><span class="ID">tree</span><span class="Operator">.</span><span class="ID">AppendItem</span><span class="Operator">(</span><span class="ID">parentItem</span><span class="Operator">,</span> <span class="ID">item</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  27 </span>            <span class="ResWord">else</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  28 </span>                <span class="ID">newItem</span> <span class="Operator">=</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">tree</span><span class="Operator">.</span><span class="ID">AppendItem</span><span class="Operator">(</span><span class="ID">parentItem</span><span class="Operator">,</span> <span class="ID">item</span><span class="Operator">[</span><span class="Number">0</span><span class="Operator">]</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  29 </span>                <span class="ID">self</span><span class="Operator">.</span><span class="ID">AddTreeNodes</span><span class="Operator">(</span><span class="ID">newItem</span><span class="Operator">,</span> <span class="ID">item</span><span class="Operator">[</span><span class="Number">1</span><span class="Operator">]</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  30 </span></span>
<span class="line"><span class="LineNumber">  31 </span>    <span class="ResWord">def</span> <span class="ID">GetItemText</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">item</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  32 </span>        <span class="ResWord">if</span> <span class="ID">item</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  33 </span>            <span class="ResWord">return</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">tree</span><span class="Operator">.</span><span class="ID">GetItemText</span><span class="Operator">(</span><span class="ID">item</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  34 </span>        <span class="ResWord">else</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  35 </span>            <span class="ResWord">return</span> <span class="String">""</span></span>
<span class="line"><span class="LineNumber">  36 </span></span>
<span class="line"><span class="LineNumber">  37 </span>    <span class="ResWord">def</span> <span class="ID">OnItemExpanded</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">evt</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  38 </span>        <span class="ResWord">print</span> <span class="String">"OnItemExpanded: "</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">GetItemText</span><span class="Operator">(</span><span class="ID">evt</span><span class="Operator">.</span><span class="ID">GetItem</span><span class="Operator">(</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  39 </span></span>
<span class="line"><span class="LineNumber">  40 </span>    <span class="ResWord">def</span> <span class="ID">OnItemCollapsed</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">evt</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  41 </span>        <span class="ResWord">print</span> <span class="String">"OnItemCollapsed:"</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">GetItemText</span><span class="Operator">(</span><span class="ID">evt</span><span class="Operator">.</span><span class="ID">GetItem</span><span class="Operator">(</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  42 </span>    <span class="ResWord">def</span> <span class="ID">OnSelChanged</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">evt</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  43 </span>        <span class="ResWord">print</span> <span class="String">"OnSelChanged:   "</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">GetItemText</span><span class="Operator">(</span><span class="ID">evt</span><span class="Operator">.</span><span class="ID">GetItem</span><span class="Operator">(</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  44 </span>    <span class="ResWord">def</span> <span class="ID">OnActivated</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">evt</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  45 </span>        <span class="ResWord">print</span> <span class="String">"OnActivated:    "</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">GetItemText</span><span class="Operator">(</span><span class="ID">evt</span><span class="Operator">.</span><span class="ID">GetItem</span><span class="Operator">(</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  46 </span><span class="ID">app</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">PySimpleApp</span><span class="Operator">(</span><span class="ID">redirect</span><span class="Operator">=</span><span class="ID">True</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  47 </span><span class="ID">frame</span> <span class="Operator">=</span> <span class="ID">TestFrame</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  48 </span><span class="ID">frame</span><span class="Operator">.</span><span class="ID">Show</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  49 </span><span class="ID">app</span><span class="Operator">.</span><span class="ID">MainLoop</span><span class="Operator">(</span><span class="Operator">)</span><span class="Text"></span></span>
</pre>
</div>
<span id="line-74" class="anchor"></span><p class="line862">下面的<tt>wx.TreeCtrl</tt>的构造函数是一个典型的<tt>wxPython</tt>窗口部件构造函数： <span id="line-75" class="anchor"></span><span id="line-76" class="anchor"></span></p>
<p class="line867"><span id="line-77" class="anchor"></span><span id="line-78" class="anchor"></span><span id="line-79" class="anchor"></span><span id="line-80" class="anchor"></span><span id="line-81" class="anchor"></span></p>
<div lang="en" dir="ltr" class="codearea">
<script type="text/javascript">
document.write('<a href="#" onclick="return togglenumber(\'CA-b23c015b3324af5b60cbedcc2ecb1a43d7e2c849_001\', 1, 1);" \
class="codenumbers">切换行号显示<\/a>');
</script><a class="codenumbers" onclick="return togglenumber('CA-b23c015b3324af5b60cbedcc2ecb1a43d7e2c849_001', 1, 1);" href="#">切换行号显示</a>
<pre lang="en" id="CA-b23c015b3324af5b60cbedcc2ecb1a43d7e2c849_001" dir="ltr"><span class="line"><span class="LineNumber">   1 </span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">TreeControl</span><span class="Operator">(</span><span class="ID">parent</span><span class="Operator">,</span> <span class="ID">id</span><span class="Operator">=</span><span class="Operator">-</span><span class="Number">1</span><span class="Operator">,</span> <span class="ID">pos</span><span class="Operator">=</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">DefaultPosition</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">   2 </span>        <span class="ID">size</span><span class="Operator">=</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">DefaultSize</span><span class="Operator">,</span> <span class="ID">style</span><span class="Operator">=</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">TR_HAS_BUTTONS</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">   3 </span>        <span class="ID">validator</span><span class="Operator">=</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">DefaultValidator</span><span class="Operator">,</span> <span class="ID">name</span><span class="Operator">=</span><span class="String">"treeCtrl"</span><span class="Operator">)</span><span class="Text"></span></span>
</pre>
</div>
<span id="line-82" class="anchor"></span><p class="line862">其中的参数意义与通常的<tt>wx.Window</tt>对象相同。该构造函数提供给你了一个没有元素的空的树。 <span id="line-83" class="anchor"></span><span id="line-84" class="anchor"></span></p>
<p class="line867"><strong>另附<tt>data.py</tt>文件</strong>： <span id="line-85" class="anchor"></span><span id="line-86" class="anchor"></span></p>
<p class="line867"><span id="line-87" class="anchor"></span><span id="line-88" class="anchor"></span><span id="line-89" class="anchor"></span><span id="line-90" class="anchor"></span><span id="line-91" class="anchor"></span><span id="line-92" class="anchor"></span><span id="line-93" class="anchor"></span><span id="line-94" class="anchor"></span><span id="line-95" class="anchor"></span><span id="line-96" class="anchor"></span><span id="line-97" class="anchor"></span><span id="line-98" class="anchor"></span><span id="line-99" class="anchor"></span><span id="line-100" class="anchor"></span><span id="line-101" class="anchor"></span><span id="line-102" class="anchor"></span><span id="line-103" class="anchor"></span><span id="line-104" class="anchor"></span><span id="line-105" class="anchor"></span><span id="line-106" class="anchor"></span><span id="line-107" class="anchor"></span><span id="line-108" class="anchor"></span><span id="line-109" class="anchor"></span><span id="line-110" class="anchor"></span><span id="line-111" class="anchor"></span><span id="line-112" class="anchor"></span><span id="line-113" class="anchor"></span><span id="line-114" class="anchor"></span><span id="line-115" class="anchor"></span><span id="line-116" class="anchor"></span><span id="line-117" class="anchor"></span><span id="line-118" class="anchor"></span><span id="line-119" class="anchor"></span><span id="line-120" class="anchor"></span><span id="line-121" class="anchor"></span><span id="line-122" class="anchor"></span><span id="line-123" class="anchor"></span><span id="line-124" class="anchor"></span><span id="line-125" class="anchor"></span><span id="line-126" class="anchor"></span><span id="line-127" class="anchor"></span><span id="line-128" class="anchor"></span><span id="line-129" class="anchor"></span><span id="line-130" class="anchor"></span><span id="line-131" class="anchor"></span><span id="line-132" class="anchor"></span><span id="line-133" class="anchor"></span><span id="line-134" class="anchor"></span><span id="line-135" class="anchor"></span><span id="line-136" class="anchor"></span><span id="line-137" class="anchor"></span><span id="line-138" class="anchor"></span><span id="line-139" class="anchor"></span><span id="line-140" class="anchor"></span><span id="line-141" class="anchor"></span><span id="line-142" class="anchor"></span><span id="line-143" class="anchor"></span><span id="line-144" class="anchor"></span><span id="line-145" class="anchor"></span><span id="line-146" class="anchor"></span><span id="line-147" class="anchor"></span><span id="line-148" class="anchor"></span><span id="line-149" class="anchor"></span><span id="line-150" class="anchor"></span><span id="line-151" class="anchor"></span><span id="line-152" class="anchor"></span><span id="line-153" class="anchor"></span><span id="line-154" class="anchor"></span><span id="line-155" class="anchor"></span><span id="line-156" class="anchor"></span><span id="line-157" class="anchor"></span><span id="line-158" class="anchor"></span><span id="line-159" class="anchor"></span><span id="line-160" class="anchor"></span><span id="line-161" class="anchor"></span><span id="line-162" class="anchor"></span><span id="line-163" class="anchor"></span><span id="line-164" class="anchor"></span><span id="line-165" class="anchor"></span><span id="line-166" class="anchor"></span><span id="line-167" class="anchor"></span><span id="line-168" class="anchor"></span><span id="line-169" class="anchor"></span><span id="line-170" class="anchor"></span><span id="line-171" class="anchor"></span><span id="line-172" class="anchor"></span><span id="line-173" class="anchor"></span><span id="line-174" class="anchor"></span><span id="line-175" class="anchor"></span><span id="line-176" class="anchor"></span><span id="line-177" class="anchor"></span><span id="line-178" class="anchor"></span><span id="line-179" class="anchor"></span><span id="line-180" class="anchor"></span><span id="line-181" class="anchor"></span><span id="line-182" class="anchor"></span><span id="line-183" class="anchor"></span><span id="line-184" class="anchor"></span><span id="line-185" class="anchor"></span><span id="line-186" class="anchor"></span><span id="line-187" class="anchor"></span><span id="line-188" class="anchor"></span><span id="line-189" class="anchor"></span><span id="line-190" class="anchor"></span><span id="line-191" class="anchor"></span><span id="line-192" class="anchor"></span><span id="line-193" class="anchor"></span><span id="line-194" class="anchor"></span><span id="line-195" class="anchor"></span><span id="line-196" class="anchor"></span><span id="line-197" class="anchor"></span><span id="line-198" class="anchor"></span><span id="line-199" class="anchor"></span><span id="line-200" class="anchor"></span><span id="line-201" class="anchor"></span><span id="line-202" class="anchor"></span><span id="line-203" class="anchor"></span><span id="line-204" class="anchor"></span><span id="line-205" class="anchor"></span><span id="line-206" class="anchor"></span><span id="line-207" class="anchor"></span><span id="line-208" class="anchor"></span><span id="line-209" class="anchor"></span><span id="line-210" class="anchor"></span><span id="line-211" class="anchor"></span><span id="line-212" class="anchor"></span><span id="line-213" class="anchor"></span><span id="line-214" class="anchor"></span><span id="line-215" class="anchor"></span><span id="line-216" class="anchor"></span><span id="line-217" class="anchor"></span><span id="line-218" class="anchor"></span><span id="line-219" class="anchor"></span><span id="line-220" class="anchor"></span><span id="line-221" class="anchor"></span><span id="line-222" class="anchor"></span><span id="line-223" class="anchor"></span><span id="line-224" class="anchor"></span><span id="line-225" class="anchor"></span><span id="line-226" class="anchor"></span><span id="line-227" class="anchor"></span><span id="line-228" class="anchor"></span><span id="line-229" class="anchor"></span><span id="line-230" class="anchor"></span><span id="line-231" class="anchor"></span><span id="line-232" class="anchor"></span><span id="line-233" class="anchor"></span><span id="line-234" class="anchor"></span><span id="line-235" class="anchor"></span><span id="line-236" class="anchor"></span><span id="line-237" class="anchor"></span><span id="line-238" class="anchor"></span><span id="line-239" class="anchor"></span><span id="line-240" class="anchor"></span><span id="line-241" class="anchor"></span><span id="line-242" class="anchor"></span><span id="line-243" class="anchor"></span><span id="line-244" class="anchor"></span><span id="line-245" class="anchor"></span><span id="line-246" class="anchor"></span><span id="line-247" class="anchor"></span><span id="line-248" class="anchor"></span><span id="line-249" class="anchor"></span><span id="line-250" class="anchor"></span><span id="line-251" class="anchor"></span><span id="line-252" class="anchor"></span><span id="line-253" class="anchor"></span><span id="line-254" class="anchor"></span><span id="line-255" class="anchor"></span><span id="line-256" class="anchor"></span><span id="line-257" class="anchor"></span><span id="line-258" class="anchor"></span><span id="line-259" class="anchor"></span><span id="line-260" class="anchor"></span><span id="line-261" class="anchor"></span><span id="line-262" class="anchor"></span><span id="line-263" class="anchor"></span><span id="line-264" class="anchor"></span><span id="line-265" class="anchor"></span><span id="line-266" class="anchor"></span><span id="line-267" class="anchor"></span><span id="line-268" class="anchor"></span><span id="line-269" class="anchor"></span><span id="line-270" class="anchor"></span><span id="line-271" class="anchor"></span><span id="line-272" class="anchor"></span><span id="line-273" class="anchor"></span><span id="line-274" class="anchor"></span><span id="line-275" class="anchor"></span><span id="line-276" class="anchor"></span><span id="line-277" class="anchor"></span><span id="line-278" class="anchor"></span><span id="line-279" class="anchor"></span><span id="line-280" class="anchor"></span><span id="line-281" class="anchor"></span><span id="line-282" class="anchor"></span><span id="line-283" class="anchor"></span><span id="line-284" class="anchor"></span><span id="line-285" class="anchor"></span><span id="line-286" class="anchor"></span><span id="line-287" class="anchor"></span><span id="line-288" class="anchor"></span><span id="line-289" class="anchor"></span><span id="line-290" class="anchor"></span><span id="line-291" class="anchor"></span><span id="line-292" class="anchor"></span><span id="line-293" class="anchor"></span><span id="line-294" class="anchor"></span><span id="line-295" class="anchor"></span><span id="line-296" class="anchor"></span><span id="line-297" class="anchor"></span><span id="line-298" class="anchor"></span><span id="line-299" class="anchor"></span><span id="line-300" class="anchor"></span><span id="line-301" class="anchor"></span><span id="line-302" class="anchor"></span><span id="line-303" class="anchor"></span><span id="line-304" class="anchor"></span><span id="line-305" class="anchor"></span><span id="line-306" class="anchor"></span><span id="line-307" class="anchor"></span><span id="line-308" class="anchor"></span><span id="line-309" class="anchor"></span><span id="line-310" class="anchor"></span><span id="line-311" class="anchor"></span><span id="line-312" class="anchor"></span><span id="line-313" class="anchor"></span><span id="line-314" class="anchor"></span><span id="line-315" class="anchor"></span><span id="line-316" class="anchor"></span><span id="line-317" class="anchor"></span><span id="line-318" class="anchor"></span><span id="line-319" class="anchor"></span><span id="line-320" class="anchor"></span><span id="line-321" class="anchor"></span><span id="line-322" class="anchor"></span><span id="line-323" class="anchor"></span><span id="line-324" class="anchor"></span><span id="line-325" class="anchor"></span><span id="line-326" class="anchor"></span><span id="line-327" class="anchor"></span><span id="line-328" class="anchor"></span><span id="line-329" class="anchor"></span><span id="line-330" class="anchor"></span><span id="line-331" class="anchor"></span><span id="line-332" class="anchor"></span><span id="line-333" class="anchor"></span><span id="line-334" class="anchor"></span><span id="line-335" class="anchor"></span><span id="line-336" class="anchor"></span><span id="line-337" class="anchor"></span><span id="line-338" class="anchor"></span><span id="line-339" class="anchor"></span><span id="line-340" class="anchor"></span><span id="line-341" class="anchor"></span><span id="line-342" class="anchor"></span><span id="line-343" class="anchor"></span><span id="line-344" class="anchor"></span><span id="line-345" class="anchor"></span><span id="line-346" class="anchor"></span><span id="line-347" class="anchor"></span><span id="line-348" class="anchor"></span><span id="line-349" class="anchor"></span><span id="line-350" class="anchor"></span><span id="line-351" class="anchor"></span><span id="line-352" class="anchor"></span><span id="line-353" class="anchor"></span><span id="line-354" class="anchor"></span><span id="line-355" class="anchor"></span><span id="line-356" class="anchor"></span><span id="line-357" class="anchor"></span><span id="line-358" class="anchor"></span><span id="line-359" class="anchor"></span><span id="line-360" class="anchor"></span><span id="line-361" class="anchor"></span><span id="line-362" class="anchor"></span><span id="line-363" class="anchor"></span><span id="line-364" class="anchor"></span><span id="line-365" class="anchor"></span><span id="line-366" class="anchor"></span><span id="line-367" class="anchor"></span><span id="line-368" class="anchor"></span><span id="line-369" class="anchor"></span><span id="line-370" class="anchor"></span><span id="line-371" class="anchor"></span><span id="line-372" class="anchor"></span><span id="line-373" class="anchor"></span><span id="line-374" class="anchor"></span><span id="line-375" class="anchor"></span><span id="line-376" class="anchor"></span><span id="line-377" class="anchor"></span><span id="line-378" class="anchor"></span><span id="line-379" class="anchor"></span><span id="line-380" class="anchor"></span><span id="line-381" class="anchor"></span><span id="line-382" class="anchor"></span><span id="line-383" class="anchor"></span><span id="line-384" class="anchor"></span><span id="line-385" class="anchor"></span><span id="line-386" class="anchor"></span><span id="line-387" class="anchor"></span><span id="line-388" class="anchor"></span><span id="line-389" class="anchor"></span><span id="line-390" class="anchor"></span><span id="line-391" class="anchor"></span><span id="line-392" class="anchor"></span><span id="line-393" class="anchor"></span><span id="line-394" class="anchor"></span><span id="line-395" class="anchor"></span><span id="line-396" class="anchor"></span><span id="line-397" class="anchor"></span><span id="line-398" class="anchor"></span><span id="line-399" class="anchor"></span><span id="line-400" class="anchor"></span><span id="line-401" class="anchor"></span><span id="line-402" class="anchor"></span><span id="line-403" class="anchor"></span><span id="line-404" class="anchor"></span><span id="line-405" class="anchor"></span><span id="line-406" class="anchor"></span><span id="line-407" class="anchor"></span><span id="line-408" class="anchor"></span><span id="line-409" class="anchor"></span><span id="line-410" class="anchor"></span><span id="line-411" class="anchor"></span><span id="line-412" class="anchor"></span><span id="line-413" class="anchor"></span><span id="line-414" class="anchor"></span><span id="line-415" class="anchor"></span><span id="line-416" class="anchor"></span><span id="line-417" class="anchor"></span><span id="line-418" class="anchor"></span><span id="line-419" class="anchor"></span><span id="line-420" class="anchor"></span><span id="line-421" class="anchor"></span><span id="line-422" class="anchor"></span><span id="line-423" class="anchor"></span><span id="line-424" class="anchor"></span><span id="line-425" class="anchor"></span><span id="line-426" class="anchor"></span><span id="line-427" class="anchor"></span><span id="line-428" class="anchor"></span><span id="line-429" class="anchor"></span><span id="line-430" class="anchor"></span><span id="line-431" class="anchor"></span><span id="line-432" class="anchor"></span><span id="line-433" class="anchor"></span><span id="line-434" class="anchor"></span><span id="line-435" class="anchor"></span><span id="line-436" class="anchor"></span><span id="line-437" class="anchor"></span><span id="line-438" class="anchor"></span><span id="line-439" class="anchor"></span><span id="line-440" class="anchor"></span><span id="line-441" class="anchor"></span><span id="line-442" class="anchor"></span><span id="line-443" class="anchor"></span><span id="line-444" class="anchor"></span><span id="line-445" class="anchor"></span><span id="line-446" class="anchor"></span><span id="line-447" class="anchor"></span><span id="line-448" class="anchor"></span><span id="line-449" class="anchor"></span><span id="line-450" class="anchor"></span><span id="line-451" class="anchor"></span><span id="line-452" class="anchor"></span><span id="line-453" class="anchor"></span><span id="line-454" class="anchor"></span><span id="line-455" class="anchor"></span><span id="line-456" class="anchor"></span><span id="line-457" class="anchor"></span><span id="line-458" class="anchor"></span><span id="line-459" class="anchor"></span><span id="line-460" class="anchor"></span><span id="line-461" class="anchor"></span><span id="line-462" class="anchor"></span><span id="line-463" class="anchor"></span><span id="line-464" class="anchor"></span><span id="line-465" class="anchor"></span><span id="line-466" class="anchor"></span><span id="line-467" class="anchor"></span><span id="line-468" class="anchor"></span><span id="line-469" class="anchor"></span><span id="line-470" class="anchor"></span><span id="line-471" class="anchor"></span><span id="line-472" class="anchor"></span><span id="line-473" class="anchor"></span><span id="line-474" class="anchor"></span><span id="line-475" class="anchor"></span><span id="line-476" class="anchor"></span><span id="line-477" class="anchor"></span><span id="line-478" class="anchor"></span><span id="line-479" class="anchor"></span><span id="line-480" class="anchor"></span><span id="line-481" class="anchor"></span><span id="line-482" class="anchor"></span><span id="line-483" class="anchor"></span><span id="line-484" class="anchor"></span><span id="line-485" class="anchor"></span></p>
<div lang="en" dir="ltr" class="codearea">
<script type="text/javascript">
document.write('<a href="#" onclick="return togglenumber(\'CA-43ecfa3189d506e481894573a6f1ba443fde0237_002\', 1, 1);" \
class="codenumbers">切换行号显示<\/a>');
</script><a class="codenumbers" onclick="return togglenumber('CA-43ecfa3189d506e481894573a6f1ba443fde0237_002', 1, 1);" href="#">切换行号显示</a>
<pre lang="en" id="CA-43ecfa3189d506e481894573a6f1ba443fde0237_002" dir="ltr"><span class="line"><span class="LineNumber">   1 </span><span class="Comment"># Some sample data for the treectrl samples</span></span>
<span class="line"><span class="LineNumber">   2 </span><span class="Comment"></span><span class="ID">tree</span> <span class="Operator">=</span> <span class="Operator">[</span></span>
<span class="line"><span class="LineNumber">   3 </span>    <span class="String">"wx.AcceleratorTable"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">   4 </span>    <span class="String">"wx.BrushList"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">   5 </span>    <span class="String">"wx.BusyInfo"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">   6 </span>    <span class="String">"wx.Clipboard"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">   7 </span>    <span class="String">"wx.Colour"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">   8 </span>    <span class="String">"wx.ColourData"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">   9 </span>    <span class="String">"wx.ColourDatabase"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">  10 </span>    <span class="String">"wx.ContextHelp"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">  11 </span>    <span class="Operator">[</span><span class="String">"wx.DC"</span><span class="Operator">,</span> <span class="Operator">[</span></span>
<span class="line"><span class="LineNumber">  12 </span>          <span class="String">"wx.ClientDC"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">  13 </span>          <span class="Operator">[</span><span class="String">"wx.MemoryDC"</span><span class="Operator">,</span> <span class="Operator">[</span></span>
<span class="line"><span class="LineNumber">  14 </span>                <span class="String">"wx.lib.colourchooser.canvas.BitmapBuffer"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">  15 </span>                <span class="Operator">[</span><span class="String">"wx.BufferedDC"</span><span class="Operator">,</span> <span class="Operator">[</span></span>
<span class="line"><span class="LineNumber">  16 </span>                      <span class="String">"wx.BufferedPaintDC"</span><span class="Operator">,</span> <span class="Operator">]</span><span class="Operator">]</span><span class="Operator">]</span><span class="Operator">]</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">  17 </span>          <span class="String">"wx.MetaFileDC"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">  18 </span>          <span class="String">"wx.MirrorDC"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">  19 </span>          <span class="String">"wx.PaintDC"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">  20 </span>          <span class="String">"wx.PostScriptDC"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">  21 </span>          <span class="String">"wx.PrinterDC"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">  22 </span>          <span class="String">"wx.ScreenDC"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">  23 </span>          <span class="String">"wx.WindowDC"</span><span class="Operator">,</span><span class="Operator">]</span><span class="Operator">]</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">  24 </span>    <span class="String">"wx.DragImage"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">  25 </span>    <span class="String">"wx.Effects"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">  26 </span>    <span class="String">"wx.EncodingConverter"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">  27 </span>    <span class="Operator">[</span><span class="String">"wx.Event"</span><span class="Operator">,</span> <span class="Operator">[</span></span>
<span class="line"><span class="LineNumber">  28 </span>          <span class="String">"wx.ActivateEvent"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">  29 </span>          <span class="String">"wx.CalculateLayoutEvent"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">  30 </span>          <span class="String">"wx.CloseEvent"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">  31 </span>          <span class="Operator">[</span><span class="String">"wx.CommandEvent"</span><span class="Operator">,</span> <span class="Operator">[</span></span>
<span class="line"><span class="LineNumber">  32 </span>                <span class="String">"wx.calendar.CalendarEvent"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">  33 </span>                <span class="String">"wx.ChildFocusEvent"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">  34 </span>                <span class="String">"wx.ContextMenuEvent"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">  35 </span>                <span class="String">"wx.gizmos.DynamicSashSplitEvent"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">  36 </span>                <span class="String">"wx.gizmos.DynamicSashUnifyEvent"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">  37 </span>                <span class="String">"wx.FindDialogEvent"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">  38 </span>                <span class="String">"wx.grid.GridEditorCreatedEvent"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">  39 </span>                <span class="String">"wx.HelpEvent"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">  40 </span>                <span class="Operator">[</span><span class="String">"wx.NotifyEvent"</span><span class="Operator">,</span><span class="Operator">[</span></span>
<span class="line"><span class="LineNumber">  41 </span>                      <span class="Operator">[</span><span class="String">"wx.BookCtrlEvent"</span><span class="Operator">,</span> <span class="Operator">[</span></span>
<span class="line"><span class="LineNumber">  42 </span>                            <span class="String">"wx.ListbookEvent"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">  43 </span>                            <span class="String">"wx.NotebookEvent "</span><span class="Operator">,</span><span class="Operator">]</span><span class="Operator">]</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">  44 </span>                      <span class="String">"wx.grid.GridEvent"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">  45 </span>                      <span class="String">"wx.grid.GridRangeSelectEvent"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">  46 </span>                      <span class="String">"wx.grid.GridSizeEvent"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">  47 </span>                      <span class="String">"wx.ListEvent"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">  48 </span>                      <span class="String">"wx.SpinEvent"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">  49 </span>                      <span class="String">"wx.SplitterEvent"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">  50 </span>                      <span class="String">"wx.TreeEvent"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">  51 </span>                      <span class="String">"wx.wizard.WizardEvent "</span><span class="Operator">,</span><span class="Operator">]</span><span class="Operator">]</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">  52 </span>                <span class="Operator">[</span><span class="String">"wx.PyCommandEvent"</span><span class="Operator">,</span> <span class="Operator">[</span></span>
<span class="line"><span class="LineNumber">  53 </span>                      <span class="String">"wx.lib.colourselect.ColourSelectEvent"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">  54 </span>                      <span class="String">"wx.lib.buttons.GenButtonEvent"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">  55 </span>                      <span class="String">"wx.lib.gridmovers.GridColMoveEvent"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">  56 </span>                      <span class="String">"wx.lib.gridmovers.GridRowMoveEvent"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">  57 </span>                      <span class="String">"wx.lib.intctrl.IntUpdatedEvent"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">  58 </span>                      <span class="String">"wx.lib.masked.combobox.MaskedComboBoxSelectEvent"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">  59 </span>                      <span class="String">"wx.lib.masked.numctrl.NumberUpdatedEvent"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">  60 </span>                      <span class="String">"wx.lib.masked.timectrl.TimeUpdatedEvent "</span><span class="Operator">,</span><span class="Operator">]</span><span class="Operator">]</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">  61 </span>                <span class="String">"wx.SashEvent"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">  62 </span>                <span class="String">"wx.ScrollEvent"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">  63 </span>                <span class="String">"wx.stc.StyledTextEvent"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">  64 </span>                <span class="String">"wx.TextUrlEvent"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">  65 </span>                <span class="String">"wx.UpdateUIEvent"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">  66 </span>                <span class="String">"wx.WindowCreateEvent"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">  67 </span>                <span class="String">"wx.WindowDestroyEvent "</span><span class="Operator">,</span><span class="Operator">]</span><span class="Operator">]</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">  68 </span>          <span class="String">"wx.DisplayChangedEvent"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">  69 </span>          <span class="String">"wx.DropFilesEvent"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">  70 </span>          <span class="String">"wx.EraseEvent"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">  71 </span>          <span class="String">"wx.FocusEvent"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">  72 </span>          <span class="String">"wx.IconizeEvent"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">  73 </span>          <span class="String">"wx.IdleEvent"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">  74 </span>          <span class="String">"wx.InitDialogEvent"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">  75 </span>          <span class="String">"wx.JoystickEvent"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">  76 </span>          <span class="String">"wx.KeyEvent"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">  77 </span>          <span class="String">"wx.MaximizeEvent"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">  78 </span>          <span class="String">"wx.MenuEvent"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">  79 </span>          <span class="String">"wx.MouseCaptureChangedEvent"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">  80 </span>          <span class="String">"wx.MouseEvent"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">  81 </span>          <span class="String">"wx.MoveEvent"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">  82 </span>          <span class="String">"wx.NavigationKeyEvent"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">  83 </span>          <span class="String">"wx.NcPaintEvent"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">  84 </span>          <span class="String">"wx.PaintEvent"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">  85 </span>          <span class="String">"wx.PaletteChangedEvent"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">  86 </span>          <span class="String">"wx.ProcessEvent"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">  87 </span>          <span class="Operator">[</span><span class="String">"wx.PyEvent"</span><span class="Operator">,</span> <span class="Operator">[</span></span>
<span class="line"><span class="LineNumber">  88 </span>                <span class="String">"wx.lib.throbber.UpdateThrobberEvent "</span><span class="Operator">,</span><span class="Operator">]</span><span class="Operator">]</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">  89 </span>          <span class="String">"wx.QueryLayoutInfoEvent"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">  90 </span>          <span class="String">"wx.QueryNewPaletteEvent"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">  91 </span>          <span class="String">"wx.ScrollWinEvent"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">  92 </span>          <span class="String">"wx.SetCursorEvent"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">  93 </span>          <span class="String">"wx.ShowEvent"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">  94 </span>          <span class="String">"wx.SizeEvent"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">  95 </span>          <span class="String">"wx.SysColourChangedEvent"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">  96 </span>          <span class="String">"wx.TaskBarIconEvent"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">  97 </span>          <span class="String">"wx.TimerEvent "</span><span class="Operator">,</span><span class="Operator">]</span><span class="Operator">]</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">  98 </span>    <span class="Operator">[</span><span class="String">"wx.EvtHandler"</span><span class="Operator">,</span> <span class="Operator">[</span></span>
<span class="line"><span class="LineNumber">  99 </span>          <span class="String">"wx.lib.gridmovers.GridColMover"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 100 </span>          <span class="String">"wx.lib.gridmovers.GridRowMover"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 101 </span>          <span class="String">"wx.html.HtmlHelpController"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 102 </span>          <span class="String">"wx.Menu"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 103 </span>          <span class="String">"wx.Process"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 104 </span>          <span class="Operator">[</span><span class="String">"wx.PyApp"</span><span class="Operator">,</span> <span class="Operator">[</span></span>
<span class="line"><span class="LineNumber"> 105 </span>                <span class="Operator">[</span><span class="String">"wx.App"</span><span class="Operator">,</span> <span class="Operator">[</span></span>
<span class="line"><span class="LineNumber"> 106 </span>                      <span class="String">"wx.py.PyAlaCarte.App"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 107 </span>                      <span class="String">"wx.py.PyAlaMode.App"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 108 </span>                      <span class="String">"wx.py.PyAlaModeTest.App"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 109 </span>                      <span class="String">"wx.py.PyCrust.App"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 110 </span>                      <span class="String">"wx.py.PyShell.App"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 111 </span>                      <span class="Operator">[</span><span class="String">"wx.py.filling.App"</span><span class="Operator">,</span> <span class="Operator">[</span></span>
<span class="line"><span class="LineNumber"> 112 </span>                            <span class="String">"wx.py.PyFilling.App "</span><span class="Operator">,</span><span class="Operator">]</span><span class="Operator">]</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 113 </span>                      <span class="Operator">[</span><span class="String">"wx.PySimpleApp"</span><span class="Operator">,</span> <span class="Operator">[</span></span>
<span class="line"><span class="LineNumber"> 114 </span>                            <span class="String">"wx.lib.masked.maskededit.test"</span><span class="Operator">,</span><span class="Operator">]</span><span class="Operator">]</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 115 </span>                      <span class="String">"wx.PyWidgetTester "</span><span class="Operator">,</span><span class="Operator">]</span><span class="Operator">]</span><span class="Operator">]</span><span class="Operator">]</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 116 </span></span>
<span class="line"><span class="LineNumber"> 117 </span>          <span class="String">"wx.TaskBarIcon"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 118 </span>          <span class="Operator">[</span><span class="String">"wx.Timer"</span><span class="Operator">,</span> <span class="Operator">[</span></span>
<span class="line"><span class="LineNumber"> 119 </span>                <span class="String">"wx.PyTimer "</span><span class="Operator">,</span><span class="Operator">]</span><span class="Operator">]</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 120 </span>          <span class="Operator">[</span><span class="String">"wx.Validator"</span><span class="Operator">,</span> <span class="Operator">[</span></span>
<span class="line"><span class="LineNumber"> 121 </span>                <span class="Operator">[</span><span class="String">"wx.PyValidator"</span><span class="Operator">,</span><span class="Operator">[</span></span>
<span class="line"><span class="LineNumber"> 122 </span>                      <span class="String">"wx.lib.intctrl.IntValidator"</span><span class="Operator">,</span><span class="Operator">]</span><span class="Operator">]</span><span class="Operator">]</span><span class="Operator">]</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 123 </span>          <span class="Operator">[</span><span class="String">"wx.Window"</span><span class="Operator">,</span> <span class="Operator">[</span></span>
<span class="line"><span class="LineNumber"> 124 </span>                <span class="Operator">[</span><span class="String">"wx.lib.colourchooser.canvas.Canvas"</span><span class="Operator">,</span> <span class="Operator">[</span></span>
<span class="line"><span class="LineNumber"> 125 </span>                      <span class="String">"wx.lib.colourchooser.pycolourslider.PyColourSlider"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 126 </span>                      <span class="String">"wx.lib.colourchooser.pypalette.PyPalette"</span><span class="Operator">,</span><span class="Operator">]</span><span class="Operator">]</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 127 </span>                <span class="String">"wx.lib.gridmovers.ColDragWindow"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 128 </span>                <span class="Operator">[</span><span class="String">"wx.Control"</span><span class="Operator">,</span><span class="Operator">[</span></span>
<span class="line"><span class="LineNumber"> 129 </span>                      <span class="Operator">[</span><span class="String">"wx.BookCtrl"</span><span class="Operator">,</span> <span class="Operator">[</span></span>
<span class="line"><span class="LineNumber"> 130 </span>                            <span class="String">"wx.Listbook"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 131 </span>                            <span class="Operator">[</span><span class="String">"wx.Notebook"</span><span class="Operator">,</span><span class="Operator">[</span></span>
<span class="line"><span class="LineNumber"> 132 </span>                                  <span class="String">"wx.py.editor.EditorNotebook"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 133 </span>                                  <span class="String">"wx.py.editor.EditorShellNotebook"</span><span class="Operator">,</span><span class="Operator">]</span><span class="Operator">]</span> <span class="Operator">]</span><span class="Operator">]</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 134 </span>                      <span class="Operator">[</span><span class="String">"wx.Button"</span><span class="Operator">,</span> <span class="Operator">[</span></span>
<span class="line"><span class="LineNumber"> 135 </span>                            <span class="Operator">[</span><span class="String">"wx.BitmapButton"</span><span class="Operator">,</span><span class="Operator">[</span></span>
<span class="line"><span class="LineNumber"> 136 </span>                                  <span class="String">"wx.lib.colourselect.ColourSelect"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 137 </span>                                  <span class="String">"wx.ContextHelpButton"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 138 </span>                                  <span class="String">"wx.lib.foldmenu.FoldOutMenu "</span><span class="Operator">,</span><span class="Operator">]</span><span class="Operator">]</span> <span class="Operator">]</span><span class="Operator">]</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 139 </span>                      <span class="String">"wx.calendar.CalendarCtrl"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 140 </span>                      <span class="String">"wx.CheckBox"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 141 </span>                      <span class="Operator">[</span><span class="String">"wx.ComboBox"</span><span class="Operator">,</span><span class="Operator">[</span></span>
<span class="line"><span class="LineNumber"> 142 </span>                            <span class="Operator">[</span><span class="String">"wx.lib.masked.combobox.BaseMaskedComboBox"</span><span class="Operator">,</span> <span class="Operator">[</span></span>
<span class="line"><span class="LineNumber"> 143 </span>                                  <span class="String">"wx.lib.masked.combobox.ComboBox"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 144 </span>                                  <span class="String">"wx.lib.masked.combobox.PreMaskedComboBox"</span><span class="Operator">,</span><span class="Operator">]</span><span class="Operator">]</span> <span class="Operator">]</span><span class="Operator">]</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 145 </span>                      <span class="Operator">[</span><span class="String">"wx.ControlWithItems"</span><span class="Operator">,</span> <span class="Operator">[</span></span>
<span class="line"><span class="LineNumber"> 146 </span>                            <span class="Operator">[</span><span class="String">"wx.Choice"</span><span class="Operator">,</span><span class="Operator">[</span></span>
<span class="line"><span class="LineNumber"> 147 </span>                                  <span class="String">"wx.DirFilterListCtrl "</span><span class="Operator">,</span><span class="Operator">]</span><span class="Operator">]</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 148 </span>                            <span class="String">"wx.ListBox"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 149 </span>                                  <span class="String">"wx.CheckListBox "</span><span class="Operator">,</span><span class="Operator">]</span><span class="Operator">]</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 150 </span>                      <span class="String">"wx.Gauge"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 151 </span>                      <span class="String">"wx.GenericDirCtrl"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 152 </span>                      <span class="String">"wx.gizmos.LEDNumberCtrl"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 153 </span>                      <span class="Operator">[</span><span class="String">"wx.ListCtrl"</span><span class="Operator">,</span><span class="Operator">[</span></span>
<span class="line"><span class="LineNumber"> 154 </span>                            <span class="String">"wx.ListView "</span><span class="Operator">,</span><span class="Operator">]</span><span class="Operator">]</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 155 </span>                      <span class="Operator">[</span><span class="String">"wx.PyControl"</span><span class="Operator">,</span><span class="Operator">[</span></span>
<span class="line"><span class="LineNumber"> 156 </span>                            <span class="String">"wx.lib.calendar.Calendar"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 157 </span>                            <span class="Operator">[</span><span class="String">"wx.lib.buttons.GenButton"</span><span class="Operator">,</span><span class="Operator">[</span></span>
<span class="line"><span class="LineNumber"> 158 </span>                                  <span class="Operator">[</span><span class="String">"wx.lib.buttons.GenBitmapButton"</span><span class="Operator">,</span><span class="Operator">[</span></span>
<span class="line"><span class="LineNumber"> 159 </span>                                        <span class="Operator">[</span><span class="String">"wx.lib.buttons.GenBitmapTextButton"</span><span class="Operator">,</span><span class="Operator">[</span></span>
<span class="line"><span class="LineNumber"> 160 </span>                                              <span class="String">"wx.lib.buttons.GenBitmapTextToggleButton"</span><span class="Operator">,</span><span class="Operator">]</span><span class="Operator">]</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 161 </span>                                        <span class="String">"wx.lib.buttons.GenBitmapToggleButton "</span><span class="Operator">,</span><span class="Operator">]</span><span class="Operator">]</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 162 </span>                                  <span class="String">"wx.lib.buttons.GenToggleButton "</span><span class="Operator">,</span><span class="Operator">]</span><span class="Operator">]</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 163 </span>                            <span class="String">"wx.lib.statbmp.GenStaticBitmap"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 164 </span>                            <span class="String">"wx.lib.stattext.GenStaticText"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 165 </span>                            <span class="String">"wx.lib.popupctl.PopButton"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 166 </span>                            <span class="String">"wx.lib.popupctl.PopupControl"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 167 </span>                            <span class="String">"wx.lib.ticker.Ticker "</span><span class="Operator">,</span><span class="Operator">]</span><span class="Operator">]</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 168 </span>                      <span class="String">"wx.RadioBox"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 169 </span>                      <span class="String">"wx.RadioButton"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 170 </span>                      <span class="String">"wx.ScrollBar"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 171 </span>                      <span class="String">"wx.Slider"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 172 </span>                      <span class="String">"wx.SpinButton"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 173 </span>                      <span class="String">"wx.SpinCtrl"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 174 </span>                      <span class="Operator">[</span><span class="String">"wx.StaticBitmap"</span><span class="Operator">,</span><span class="Operator">[</span></span>
<span class="line"><span class="LineNumber"> 175 </span>                            <span class="String">"wx.lib.fancytext.StaticFancyText "</span><span class="Operator">,</span><span class="Operator">]</span><span class="Operator">]</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 176 </span>                      <span class="String">"wx.StaticBox"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 177 </span>                      <span class="String">"wx.StaticLine"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 178 </span>                      <span class="String">"wx.StaticText"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 179 </span>                      <span class="Operator">[</span><span class="String">"wx.stc.StyledTextCtrl"</span><span class="Operator">,</span><span class="Operator">[</span></span>
<span class="line"><span class="LineNumber"> 180 </span>                            <span class="Operator">[</span><span class="String">"wx.py.editwindow.EditWindow"</span><span class="Operator">,</span><span class="Operator">[</span></span>
<span class="line"><span class="LineNumber"> 181 </span>                                  <span class="String">"wx.py.crust.Display"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 182 </span>                                  <span class="String">"wx.py.editor.EditWindow"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 183 </span>                                  <span class="String">"wx.py.filling.FillingText"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 184 </span>                                  <span class="String">"wx.py.shell.Shell"</span><span class="Operator">,</span><span class="Operator">]</span><span class="Operator">]</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 185 </span>                            <span class="String">"wx.lib.pyshell.PyShellWindow "</span><span class="Operator">,</span><span class="Operator">]</span><span class="Operator">]</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 186 </span>                      <span class="Operator">[</span><span class="String">"wx.TextCtrl"</span><span class="Operator">,</span> <span class="Operator">[</span></span>
<span class="line"><span class="LineNumber"> 187 </span>                            <span class="Operator">[</span><span class="String">"wx.lib.masked.textctrl.BaseMaskedTextCtrl"</span><span class="Operator">,</span><span class="Operator">[</span></span>
<span class="line"><span class="LineNumber"> 188 </span>                                  <span class="String">"wx.lib.masked.ipaddrctrl.IpAddrCtrl"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 189 </span>                                  <span class="String">"wx.lib.masked.numctrl.NumCtrl"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 190 </span>                                  <span class="String">"wx.lib.masked.textctrl.PreMaskedTextCtrl"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 191 </span>                                  <span class="String">"wx.lib.masked.textctrl.TextCtrl"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 192 </span>                                  <span class="String">"wx.lib.masked.timectrl.TimeCtrl "</span><span class="Operator">,</span><span class="Operator">]</span><span class="Operator">]</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 193 </span>                            <span class="String">"wx.py.crust.Calltip"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 194 </span>                            <span class="String">"wx.lib.sheet.CTextCellEditor"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 195 </span>                            <span class="String">"wx.py.crust.DispatcherListing"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 196 </span>                            <span class="String">"wx.lib.intctrl.IntCtrl"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 197 </span>                            <span class="String">"wx.lib.rightalign.RightTextCtrl"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 198 </span>                            <span class="String">"wx.py.crust.SessionListing"</span><span class="Operator">,</span><span class="Operator">]</span><span class="Operator">]</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 199 </span>                      <span class="String">"wx.ToggleButton"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 200 </span>                      <span class="String">"wx.ToolBar"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 201 </span>                      <span class="Operator">[</span><span class="String">"wx.TreeCtrl"</span><span class="Operator">,</span><span class="Operator">[</span></span>
<span class="line"><span class="LineNumber"> 202 </span>                            <span class="String">"wx.py.filling.FillingTree"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 203 </span>                            <span class="String">"wx.gizmos.RemotelyScrolledTreeCtrl "</span><span class="Operator">,</span><span class="Operator">]</span><span class="Operator">]</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 204 </span>                      <span class="String">"wx.gizmos.TreeListCtrl "</span><span class="Operator">,</span><span class="Operator">]</span><span class="Operator">]</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 205 </span>                <span class="String">"wx.gizmos.DynamicSashWindow"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 206 </span>                <span class="String">"wx.lib.multisash.EmptyChild"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 207 </span>                <span class="String">"wx.glcanvas.GLCanvas"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 208 </span>                <span class="String">"wx.lib.imagebrowser.ImageView"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 209 </span>                <span class="String">"wx.MDIClientWindow"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 210 </span>                <span class="String">"wx.MenuBar"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 211 </span>                <span class="String">"wx.lib.multisash.MultiClient"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 212 </span>                <span class="String">"wx.lib.multisash.MultiCloser"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 213 </span>                <span class="String">"wx.lib.multisash.MultiCreator"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 214 </span>                <span class="String">"wx.lib.multisash.MultiSash"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 215 </span>                <span class="String">"wx.lib.multisash.MultiSizer"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 216 </span>                <span class="String">"wx.lib.multisash.MultiSplit"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 217 </span>                <span class="String">"wx.lib.multisash.MultiViewLeaf"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 218 </span>                <span class="Operator">[</span><span class="String">"wx.Panel"</span><span class="Operator">,</span><span class="Operator">[</span></span>
<span class="line"><span class="LineNumber"> 219 </span>                      <span class="String">"wx.gizmos.EditableListBox"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 220 </span>                      <span class="Operator">[</span><span class="String">"wx.lib.filebrowsebutton.FileBrowseButton"</span><span class="Operator">,</span><span class="Operator">[</span></span>
<span class="line"><span class="LineNumber"> 221 </span>                            <span class="String">"wx.lib.filebrowsebutton.DirBrowseButton"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 222 </span>                            <span class="String">"wx.lib.filebrowsebutton.FileBrowseButtonWithHistory"</span><span class="Operator">,</span><span class="Operator">]</span><span class="Operator">]</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 223 </span>                      <span class="String">"wx.lib.floatcanvas.FloatCanvas.FloatCanvas"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 224 </span>                      <span class="String">"wx.lib.floatcanvas.NavCanvas.NavCanvas"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 225 </span>                      <span class="String">"wx.NotebookPage"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 226 </span>                      <span class="Operator">[</span><span class="String">"wx.PreviewControlBar"</span><span class="Operator">,</span><span class="Operator">[</span></span>
<span class="line"><span class="LineNumber"> 227 </span>                            <span class="String">"wx.PyPreviewControlBar "</span><span class="Operator">,</span><span class="Operator">]</span><span class="Operator">]</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 228 </span>                      <span class="String">"wx.lib.colourchooser.pycolourbox.PyColourBox"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 229 </span>                      <span class="String">"wx.lib.colourchooser.pycolourchooser.PyColourChooser"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 230 </span>                      <span class="Operator">[</span><span class="String">"wx.PyPanel"</span><span class="Operator">,</span><span class="Operator">[</span></span>
<span class="line"><span class="LineNumber"> 231 </span>                            <span class="String">"wx.lib.throbber.Throbber"</span><span class="Operator">,</span><span class="Operator">]</span><span class="Operator">]</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 232 </span>                      <span class="String">"wx.lib.shell.PyShell"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 233 </span>                      <span class="String">"wx.lib.shell.PyShellInput"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 234 </span>                      <span class="String">"wx.lib.shell.PyShellOutput"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 235 </span>                      <span class="Operator">[</span><span class="String">"wx.ScrolledWindow"</span><span class="Operator">,</span><span class="Operator">[</span></span>
<span class="line"><span class="LineNumber"> 236 </span>                            <span class="String">"wx.lib.editor.editor.Editor"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 237 </span>                            <span class="Operator">[</span><span class="String">"wx.grid.Grid"</span><span class="Operator">,</span><span class="Operator">[</span></span>
<span class="line"><span class="LineNumber"> 238 </span>                                  <span class="String">"wx.lib.sheet.CSheet "</span><span class="Operator">,</span><span class="Operator">]</span><span class="Operator">]</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 239 </span>                            <span class="Operator">[</span><span class="String">"wx.html.HtmlWindow"</span><span class="Operator">,</span><span class="Operator">[</span></span>
<span class="line"><span class="LineNumber"> 240 </span>                                  <span class="String">"wx.lib.ClickableHtmlWindow.PyClickableHtmlWindow"</span><span class="Operator">,</span><span class="Operator">]</span><span class="Operator">]</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 241 </span>                            <span class="String">"wx.PreviewCanvas"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 242 </span>                            <span class="String">"wx.lib.printout.PrintTableDraw"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 243 </span>                            <span class="Operator">[</span><span class="String">"wx.PyScrolledWindow"</span><span class="Operator">,</span><span class="Operator">[</span></span>
<span class="line"><span class="LineNumber"> 244 </span>                                  <span class="String">"wx.lib.scrolledpanel.ScrolledPanel"</span><span class="Operator">,</span><span class="Operator">]</span><span class="Operator">]</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 245 </span>                            <span class="String">"wx.lib.ogl.ShapeCanvas"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 246 </span>                            <span class="String">"wx.gizmos.SplitterScrolledWindow "</span><span class="Operator">,</span><span class="Operator">]</span><span class="Operator">]</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 247 </span>                      <span class="Operator">[</span><span class="String">"wx.VScrolledWindow"</span><span class="Operator">,</span><span class="Operator">[</span></span>
<span class="line"><span class="LineNumber"> 248 </span>                            <span class="Operator">[</span><span class="String">"wx.VListBox"</span><span class="Operator">,</span> <span class="Operator">[</span></span>
<span class="line"><span class="LineNumber"> 249 </span>                                  <span class="String">"wx.HtmlListBox "</span><span class="Operator">,</span><span class="Operator">]</span><span class="Operator">]</span> <span class="Operator">]</span><span class="Operator">]</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 250 </span>                      <span class="Operator">[</span><span class="String">"wx.wizard.WizardPage"</span><span class="Operator">,</span> <span class="Operator">[</span></span>
<span class="line"><span class="LineNumber"> 251 </span>                            <span class="String">"wx.wizard.PyWizardPage"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 252 </span>                            <span class="String">"wx.wizard.WizardPageSimple "</span><span class="Operator">,</span><span class="Operator">]</span><span class="Operator">]</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 253 </span>                <span class="String">"wx.lib.plot.PlotCanvas"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 254 </span>                <span class="String">"wx.lib.wxPlotCanvas.PlotCanvas"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 255 </span>                <span class="Operator">[</span><span class="String">"wx.PopupWindow"</span><span class="Operator">,</span><span class="Operator">[</span></span>
<span class="line"><span class="LineNumber"> 256 </span>                      <span class="String">"wx.lib.foldmenu.FoldOutWindow"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 257 </span>                      <span class="Operator">[</span><span class="String">"wx.PopupTransientWindow"</span><span class="Operator">,</span><span class="Operator">[</span></span>
<span class="line"><span class="LineNumber"> 258 </span>                            <span class="String">"wx.TipWindow "</span><span class="Operator">,</span><span class="Operator">]</span><span class="Operator">]</span> <span class="Operator">]</span><span class="Operator">]</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 259 </span>                <span class="Operator">[</span><span class="String">"wx.PyWindow"</span><span class="Operator">,</span> <span class="Operator">[</span></span>
<span class="line"><span class="LineNumber"> 260 </span>                      <span class="String">"wx.lib.analogclock.AnalogClockWindow"</span><span class="Operator">,</span><span class="Operator">]</span><span class="Operator">]</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 261 </span>                <span class="String">"wx.lib.gridmovers.RowDragWindow"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 262 </span>                <span class="Operator">[</span><span class="String">"wx.SashWindow"</span><span class="Operator">,</span><span class="Operator">[</span></span>
<span class="line"><span class="LineNumber"> 263 </span>                      <span class="String">"wx.SashLayoutWindow "</span><span class="Operator">,</span><span class="Operator">]</span><span class="Operator">]</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 264 </span>                <span class="String">"wx.SplashScreenWindow"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 265 </span>                <span class="Operator">[</span><span class="String">"wx.SplitterWindow"</span><span class="Operator">,</span><span class="Operator">[</span></span>
<span class="line"><span class="LineNumber"> 266 </span>                      <span class="String">"wx.py.crust.Crust"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 267 </span>                      <span class="String">"wx.py.filling.Filling"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 268 </span>                      <span class="String">"wx.gizmos.ThinSplitterWindow "</span><span class="Operator">,</span><span class="Operator">]</span><span class="Operator">]</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 269 </span>                <span class="String">"wx.StatusBar"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 270 </span>                <span class="Operator">[</span><span class="String">"wx.TopLevelWindow"</span><span class="Operator">,</span><span class="Operator">[</span></span>
<span class="line"><span class="LineNumber"> 271 </span>                      <span class="Operator">[</span><span class="String">"wx.Dialog"</span><span class="Operator">,</span><span class="Operator">[</span></span>
<span class="line"><span class="LineNumber"> 272 </span>                            <span class="String">"wx.lib.calendar.CalenDlg"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 273 </span>                            <span class="String">"wx.ColourDialog"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 274 </span>                            <span class="String">"wx.DirDialog"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 275 </span>                            <span class="String">"wx.FileDialog"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 276 </span>                            <span class="String">"wx.FindReplaceDialog"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 277 </span>                            <span class="String">"wx.FontDialog"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 278 </span>                            <span class="String">"wx.lib.imagebrowser.ImageDialog"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 279 </span>                            <span class="String">"wx.MessageDialog"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 280 </span>                            <span class="String">"wx.MultiChoiceDialog"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 281 </span>                            <span class="String">"wx.lib.dialogs.MultipleChoiceDialog"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 282 </span>                            <span class="String">"wx.PageSetupDialog"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 283 </span>                            <span class="String">"wx.lib.popupctl.PopupDialog"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 284 </span>                            <span class="String">"wx.PrintDialog"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 285 </span>                            <span class="String">"wx.lib.dialogs.ScrolledMessageDialog"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 286 </span>                            <span class="String">"wx.SingleChoiceDialog"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 287 </span>                            <span class="String">"wx.TextEntryDialog"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 288 </span>                            <span class="String">"wx.wizard.Wizard "</span><span class="Operator">,</span><span class="Operator">]</span><span class="Operator">]</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 289 </span>                      <span class="Operator">[</span><span class="String">"wx.Frame"</span><span class="Operator">,</span> <span class="Operator">[</span></span>
<span class="line"><span class="LineNumber"> 290 </span>                            <span class="String">"wx.lib.analogclockopts.ACCustomizationFrame"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 291 </span>                            <span class="String">"wx.py.filling.FillingFrame"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 292 </span>                            <span class="Operator">[</span><span class="String">"wx.py.frame.Frame"</span><span class="Operator">,</span><span class="Operator">[</span></span>
<span class="line"><span class="LineNumber"> 293 </span>                                  <span class="String">"wx.py.crust.CrustFrame"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 294 </span>                                  <span class="Operator">[</span><span class="String">"wx.py.editor.EditorFrame"</span><span class="Operator">,</span><span class="Operator">[</span></span>
<span class="line"><span class="LineNumber"> 295 </span>                                        <span class="String">"wx.py.editor.EditorNotebookFrame"</span><span class="Operator">,</span><span class="Operator">]</span><span class="Operator">]</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 296 </span>                                  <span class="String">"wx.py.shell.ShellFrame"</span><span class="Operator">,</span><span class="Operator">]</span><span class="Operator">]</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 297 </span>                            <span class="String">"wx.html.HtmlHelpFrame"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 298 </span>                            <span class="String">"wx.MDIChildFrame"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 299 </span>                            <span class="String">"wx.MDIParentFrame"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 300 </span>                            <span class="String">"wx.MiniFrame"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 301 </span>                            <span class="Operator">[</span><span class="String">"wx.PreviewFrame"</span><span class="Operator">,</span><span class="Operator">[</span></span>
<span class="line"><span class="LineNumber"> 302 </span>                                  <span class="String">"wx.PyPreviewFrame "</span><span class="Operator">,</span><span class="Operator">]</span><span class="Operator">]</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 303 </span>                            <span class="String">"wx.ProgressDialog"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 304 </span>                            <span class="String">"wx.SplashScreen"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 305 </span>                            <span class="String">"wx.lib.splashscreen.SplashScreen"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 306 </span>                            <span class="String">"wx.lib.masked.maskededit.test2"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 307 </span>                            <span class="String">"wx.lib.plot.TestFrame "</span><span class="Operator">,</span><span class="Operator">]</span><span class="Operator">]</span> <span class="Operator">]</span><span class="Operator">]</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 308 </span>                <span class="String">"wx.gizmos.TreeCompanionWindow "</span><span class="Operator">,</span><span class="Operator">]</span><span class="Operator">]</span> <span class="Operator">]</span><span class="Operator">]</span> <span class="Operator">]</span><span class="Operator">]</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 309 </span>    <span class="String">"wx.FileHistory"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 310 </span>    <span class="String">"wx.FileSystem"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 311 </span>    <span class="String">"wx.FindReplaceData"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 312 </span>    <span class="String">"wx.FontData"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 313 </span>    <span class="String">"wx.FontList"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 314 </span>    <span class="String">"wx.FSFile"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 315 </span>    <span class="Operator">[</span><span class="String">"wx.GDIObject"</span><span class="Operator">,</span><span class="Operator">[</span></span>
<span class="line"><span class="LineNumber"> 316 </span>          <span class="String">"wx.Bitmap"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 317 </span>          <span class="String">"wx.Brush"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 318 </span>          <span class="String">"wx.Cursor"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 319 </span>          <span class="String">"wx.Font"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 320 </span>          <span class="String">"wx.Icon"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 321 </span>          <span class="String">"wx.Palette"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 322 </span>          <span class="String">"wx.Pen"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 323 </span>          <span class="String">"wx.Region "</span><span class="Operator">,</span><span class="Operator">]</span><span class="Operator">]</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 324 </span>    <span class="String">"wx.glcanvas.GLContext"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 325 </span>    <span class="Operator">[</span><span class="String">"wx.grid.GridTableBase"</span><span class="Operator">,</span> <span class="Operator">[</span></span>
<span class="line"><span class="LineNumber"> 326 </span>          <span class="String">"wx.grid.GridStringTable"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 327 </span>          <span class="String">"wx.grid.PyGridTableBase "</span><span class="Operator">,</span><span class="Operator">]</span><span class="Operator">]</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 328 </span>    <span class="Operator">[</span><span class="String">"wx.html.HtmlCell"</span><span class="Operator">,</span> <span class="Operator">[</span></span>
<span class="line"><span class="LineNumber"> 329 </span>          <span class="String">"wx.html.HtmlColourCell"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 330 </span>          <span class="String">"wx.html.HtmlContainerCell"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 331 </span>          <span class="String">"wx.html.HtmlFontCell"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 332 </span>          <span class="String">"wx.html.HtmlWidgetCell"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 333 </span>          <span class="String">"wx.html.HtmlWordCell "</span><span class="Operator">,</span><span class="Operator">]</span><span class="Operator">]</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 334 </span>    <span class="String">"wx.html.HtmlDCRenderer"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 335 </span>    <span class="String">"wx.html.HtmlEasyPrinting"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 336 </span>    <span class="String">"wx.html.HtmlFilter"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 337 </span>    <span class="String">"wx.html.HtmlLinkInfo"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 338 </span>    <span class="Operator">[</span><span class="String">"wx.html.HtmlParser"</span><span class="Operator">,</span> <span class="Operator">[</span></span>
<span class="line"><span class="LineNumber"> 339 </span>          <span class="String">"wx.html.HtmlWinParser "</span><span class="Operator">,</span><span class="Operator">]</span><span class="Operator">]</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 340 </span>    <span class="String">"wx.html.HtmlTag"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 341 </span>    <span class="Operator">[</span><span class="String">"wx.html.HtmlTagHandler"</span><span class="Operator">,</span> <span class="Operator">[</span></span>
<span class="line"><span class="LineNumber"> 342 </span>          <span class="Operator">[</span><span class="String">"wx.html.HtmlWinTagHandler"</span><span class="Operator">,</span> <span class="Operator">[</span></span>
<span class="line"><span class="LineNumber"> 343 </span>                <span class="String">"wx.lib.wxpTag.wxpTagHandler "</span><span class="Operator">,</span><span class="Operator">]</span><span class="Operator">]</span> <span class="Operator">]</span><span class="Operator">]</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 344 </span>    <span class="String">"wx.Image"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 345 </span>    <span class="Operator">[</span><span class="String">"wx.ImageHandler"</span><span class="Operator">,</span> <span class="Operator">[</span></span>
<span class="line"><span class="LineNumber"> 346 </span>          <span class="Operator">[</span><span class="String">"wx.BMPHandler"</span><span class="Operator">,</span> <span class="Operator">[</span></span>
<span class="line"><span class="LineNumber"> 347 </span>                <span class="Operator">[</span><span class="String">"wx.ICOHandler"</span><span class="Operator">,</span> <span class="Operator">[</span></span>
<span class="line"><span class="LineNumber"> 348 </span>                      <span class="Operator">[</span><span class="String">"wx.CURHandler"</span><span class="Operator">,</span> <span class="Operator">[</span></span>
<span class="line"><span class="LineNumber"> 349 </span>                            <span class="String">"wx.ANIHandler "</span><span class="Operator">,</span><span class="Operator">]</span><span class="Operator">]</span> <span class="Operator">]</span><span class="Operator">]</span> <span class="Operator">]</span><span class="Operator">]</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 350 </span>          <span class="String">"wx.GIFHandler"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 351 </span>          <span class="String">"wx.JPEGHandler"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 352 </span>          <span class="String">"wx.PCXHandler"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 353 </span>          <span class="String">"wx.PNGHandler"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 354 </span>          <span class="String">"wx.PNMHandler"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 355 </span>          <span class="String">"wx.TIFFHandler"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 356 </span>          <span class="String">"wx.XPMHandler "</span><span class="Operator">,</span><span class="Operator">]</span><span class="Operator">]</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 357 </span>    <span class="String">"wx.ImageList"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 358 </span>    <span class="String">"wx.IndividualLayoutConstraint"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 359 </span>    <span class="String">"wx.LayoutAlgorithm"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 360 </span>    <span class="Operator">[</span><span class="String">"wx.LayoutConstraints"</span><span class="Operator">,</span> <span class="Operator">[</span></span>
<span class="line"><span class="LineNumber"> 361 </span>          <span class="String">"wx.lib.anchors.LayoutAnchors"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 362 </span>          <span class="String">"wx.lib.layoutf.Layoutf"</span><span class="Operator">,</span><span class="Operator">]</span><span class="Operator">]</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 363 </span>    <span class="String">"wx.ListItem"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 364 </span>    <span class="String">"wx.Mask"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 365 </span>    <span class="String">"wx.MenuItem"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 366 </span>    <span class="String">"wx.MetaFile"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 367 </span>    <span class="String">"wx.PageSetupDialogData"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 368 </span>    <span class="String">"wx.PenList"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 369 </span>    <span class="String">"wx.PrintData"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 370 </span>    <span class="String">"wx.PrintDialogData"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 371 </span>    <span class="String">"wx.Printer"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 372 </span>    <span class="Operator">[</span><span class="String">"wx.Printout"</span><span class="Operator">,</span> <span class="Operator">[</span></span>
<span class="line"><span class="LineNumber"> 373 </span>          <span class="String">"wx.html.HtmlPrintout"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 374 </span>          <span class="String">"wx.lib.plot.PlotPrintout"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 375 </span>          <span class="String">"wx.lib.printout.SetPrintout "</span><span class="Operator">,</span><span class="Operator">]</span><span class="Operator">]</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 376 </span>    <span class="Operator">[</span><span class="String">"wx.PrintPreview"</span><span class="Operator">,</span> <span class="Operator">[</span></span>
<span class="line"><span class="LineNumber"> 377 </span>          <span class="String">"wx.PyPrintPreview "</span><span class="Operator">,</span><span class="Operator">]</span><span class="Operator">]</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 378 </span>    <span class="String">"wx.RegionIterator"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 379 </span>    <span class="Operator">[</span><span class="String">"wx.Sizer"</span><span class="Operator">,</span> <span class="Operator">[</span></span>
<span class="line"><span class="LineNumber"> 380 </span>          <span class="String">"wx.BookCtrlSizer"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 381 </span>          <span class="Operator">[</span><span class="String">"wx.BoxSizer"</span><span class="Operator">,</span> <span class="Operator">[</span></span>
<span class="line"><span class="LineNumber"> 382 </span>                <span class="String">"wx.StaticBoxSizer"</span><span class="Operator">,</span> <span class="Operator">]</span><span class="Operator">]</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 383 </span>          <span class="Operator">[</span><span class="String">"wx.GridSizer"</span><span class="Operator">,</span> <span class="Operator">[</span></span>
<span class="line"><span class="LineNumber"> 384 </span>                <span class="Operator">[</span><span class="String">"wx.FlexGridSizer"</span><span class="Operator">,</span> <span class="Operator">[</span></span>
<span class="line"><span class="LineNumber"> 385 </span>                      <span class="String">"wx.GridBagSizer"</span><span class="Operator">,</span><span class="Operator">]</span><span class="Operator">]</span> <span class="Operator">]</span><span class="Operator">]</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 386 </span>          <span class="String">"wx.NotebookSizer"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 387 </span>          <span class="String">"wx.PySizer"</span><span class="Operator">,</span><span class="Operator">]</span><span class="Operator">]</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 388 </span>    <span class="Operator">[</span><span class="String">"wx.SizerItem"</span><span class="Operator">,</span> <span class="Operator">[</span></span>
<span class="line"><span class="LineNumber"> 389 </span>          <span class="String">"wx.GBSizerItem"</span><span class="Operator">,</span><span class="Operator">]</span><span class="Operator">]</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 390 </span>    <span class="String">"wx.SystemOptions"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 391 </span>    <span class="String">"wx.ToolBarToolBase"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 392 </span>    <span class="String">"wx.ToolTip"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 393 </span>    <span class="String">"wx.gizmos.TreeListColumnInfo"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 394 </span>    <span class="String">"wx.xrc.XmlDocument"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 395 </span>    <span class="String">"wx.xrc.XmlResource"</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 396 </span>    <span class="String">"wx.xrc.XmlResourceHandler "</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber"> 397 </span><span class="Operator">]</span><span class="Text"></span></span>
</pre>
</div>
<span id="line-486" class="anchor"></span><p class="line867">
</p>
<h3 id="head-90c42247cbbec5b02104dc6d6648c616b98510f9">1.1.1. 如何添加一个root(根)元素？</h3>
<span id="line-487" class="anchor"></span><p class="line862">当你将项目添加到树时，你首先必须要添加的项目是<tt>root(</tt>根)元素。添加根元素的方法如下所示： <span id="line-488" class="anchor"></span><span id="line-489" class="anchor"></span></p>
<p class="line867"><span id="line-490" class="anchor"></span></p>
<pre>AddRoot(text, image=-1, selImage=-1, data=None)
<span id="line-491" class="anchor"></span></pre>
<span id="line-492" class="anchor"></span><p class="line862">你只能添加一个根元素。如果你在已经存在一个根元素后，再添加第二根元素的话，那么<tt>wxPython</tt>将引发一个异常。其中的参数<tt>text</tt>包含用于根元素的显示字符串。参数<tt>image</tt>是图像列表中的一个索引，代表要显示在参数<tt>text</tt>旁边的图像。这个图像列表将在15.5节中作更详细的讨论，但是现在只要知道它的行为类似于用于列表控件的图像列表。参数<tt>data</tt>是一个与项目相关的数据对象，主要的目的是分类。 <span id="line-493" class="anchor"></span><span id="line-494" class="anchor"></span></p>
<p class="line867"><tt>AddRoot()</tt>方法返回一个关于根项目的<tt>ID</tt>。树形控件使用它自己的类<tt>wx.TreeItemId</tt>来管理项目。在大多数时候，你不需要关心<tt>ID</tt>的具体值，你只需要知道每个项目都有一个唯一的<tt>wx.TreeItemId</tt>就够了，并且这个值可以使用等号测试。<tt>wx.TreeItemId</tt>不映射到任何简单的类型——它的值没有任何的关联性，因为你只是把它用于相等测试。 <span id="line-495" class="anchor"></span><span id="line-496" class="anchor"></span></p>
<p class="line867">
</p>
<h3 id="head-0c57c46a9d865a1513086a3c72cb1cb9fdda5b51">1.1.2. 如何将更多的项目添加到树中？</h3>
<span id="line-497" class="anchor"></span><p class="line862">一旦你有了根元素，你就可以开始向树中添加元素了。用的最多的方法是<tt>AppendItem(parent, text, image=</tt>-1, <tt>selImage=</tt>-1,
<tt>data=None)</tt>。参数<tt>parent</tt>是已有的树项目的<tt>wx.TreeItemId</tt>，它作为新项目的父亲。参数<tt>text</tt>是显示新项目的文本字符串。参数<tt>image</tt>和<tt>selImage</tt>的意义与方法<tt>AddRoot()</tt>中的相同。该方法将新的项目放置到其父项目的孩子列表的末尾。这个方法返回新创建的项目的<tt>wx.TreeItemId</tt>。如果你想给新的项目添加子项目的话，你需要拥有这个<tt>ID</tt>。一个示例如下： <span id="line-498" class="anchor"></span><span id="line-499" class="anchor"></span></p>
<p class="line867"><span id="line-500" class="anchor"></span><span id="line-501" class="anchor"></span><span id="line-502" class="anchor"></span><span id="line-503" class="anchor"></span><span id="line-504" class="anchor"></span></p>
<div lang="en" dir="ltr" class="codearea">
<script type="text/javascript">
document.write('<a href="#" onclick="return togglenumber(\'CA-f983ce23d5b9cc7867fd87f0641a196429da9d3b_003\', 1, 1);" \
class="codenumbers">切换行号显示<\/a>');
</script><a class="codenumbers" onclick="return togglenumber('CA-f983ce23d5b9cc7867fd87f0641a196429da9d3b_003', 1, 1);" href="#">切换行号显示</a>
<pre lang="en" id="CA-f983ce23d5b9cc7867fd87f0641a196429da9d3b_003" dir="ltr"><span class="line"><span class="LineNumber">   1 </span><span class="ID">rootId</span> <span class="Operator">=</span> <span class="ID">tree</span><span class="Operator">.</span><span class="ID">AddRoot</span><span class="Operator">(</span><span class="String">"The Root"</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">   2 </span><span class="ID">childId</span> <span class="Operator">=</span> <span class="ID">tree</span><span class="Operator">.</span><span class="ID">AppendItem</span><span class="Operator">(</span><span class="ID">rootId</span><span class="Operator">,</span> <span class="String">"A Child"</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">   3 </span><span class="ID">grandChildId</span> <span class="Operator">=</span> <span class="ID">tree</span><span class="Operator">.</span><span class="ID">AppendItem</span><span class="Operator">(</span><span class="ID">childId</span><span class="Operator">,</span> <span class="String">"A Grandchild"</span><span class="Operator">)</span><span class="Text"></span></span>
</pre>
</div>
<span id="line-505" class="anchor"></span><p class="line862">上面的这个代码片断增加了一个<tt>root(</tt>根)项目，然后给根项目添加了一个子项目，然后给子项目添加了它的子项目。 <span id="line-506" class="anchor"></span><span id="line-507" class="anchor"></span></p>
<p class="line862">如果要将子项目添加到孩子列表的开头的话，使用方法<tt>PrependItem(parent, text, image=</tt>-1, <tt>selImage=</tt>-1, <tt>data=None)</tt>。 <span id="line-508" class="anchor"></span><span id="line-509" class="anchor"></span></p>
<p class="line862">如果你想将一个项目插入树的任意点上，你可以使用后面的两种方法之一。第一个是<tt>InsertItem(parent, previous, text,image=</tt>-1, <tt>selImage=</tt>-1, <tt>data=None)</tt>。其中参数<tt>previous</tt>其父项目中的子列表中的项目的<tt>wx.TreeItemId</tt>。插入的项目将放置在该项目的后面。第二个方法是<tt>InsertItemBefore(parent, before, text, image=</tt>-1, <tt>selImage=</tt>-1,
<tt>data=None)</tt>。该方法将新的项目放置在<tt>before</tt>所代表的项目之前。然而参数<tt>before</tt>不是一个项目的<tt>ID</tt>。它是项目在孩子列表中的整数索引。第二个方法返回新项目的一个<tt>wx.TreeItemId</tt>。 <span id="line-510" class="anchor"></span><span id="line-511" class="anchor"></span></p>
<p class="line867">
</p>
<h3 id="head-518f410bfee3d6b7d1156eb566f96e452087af01">1.1.3. 如何管理项目？</h3>
<span id="line-512" class="anchor"></span><p class="line862">要去掉树中的一个项目，可以使用<tt>Delete(item)</tt>方法，其中参数<tt>item</tt>是该项目的<tt>wx.TreeItemId</tt>。调用这个方法将导致一个<tt>EVT_TREE_Delete_ITEM</tt>类型的树的事件被触发。后面的章节我们将讨论树的事件类型。要删除一个项目的所有子项目，而留下该项目自身，可以使用方法<tt>DeleteChildren(item)</tt>，其中参数<tt>item</tt>也是一个<tt>wx.TreeItemId</tt>。该方法不产生一个删除事件。要清除整个树，使用方法<tt>DeleteAllItems()</tt>。该方法为每个项目生成一个删除事件，但是，这在某些老版的<tt>Windows</tt>系统上不工作。 <span id="line-513" class="anchor"></span><span id="line-514" class="anchor"></span></p>
<p class="line862">一旦你将一个项目添加到树中，你就可以使用方法<tt>GetItemText(item)</tt>来得到该项目在显示在树中的文本，其中参数<tt>item</tt>是一个<tt>wx.TreeItemId</tt>。如果你想改变一个项目的显示文本，可以使用方法<tt>SetItemText(item, text)</tt>，其中参数<tt>item</tt>是一个<tt>wx.TreeItemId</tt>，参数<tt>text</tt>是一个新的显示文本。 <span id="line-515" class="anchor"></span><span id="line-516" class="anchor"></span></p>
<p class="line862">最后，你可以使用方法<tt>GetCount()</tt>来得到树中项目的总数。如果你想得到特定项目下的子项目的数量，可以使用方法<tt>GetChildrenCount(item, recursively=True)</tt>。其中参数<tt>item</tt>是一个<tt>wx.TreeItemId</tt>，参数<tt>recursively</tt>如果为<tt>False</tt>，那么该方法只返回直接的子项目的数量，如果为<tt>True</tt>，则返回所有的子项目而不关嵌套有多深。 <span id="line-517" class="anchor"></span><span id="line-518" class="anchor"></span></p>
<p class="line867">
</p>
<h2 id="head-d481c1250a570fd22e8b42387a8e9a0fb554234c">1.2. 树控件的显示样式</h2>
<span id="line-519" class="anchor"></span><p class="line874">树控件的显示样式分为四类。第一类定义了树中显示在父项目的文本旁的按钮（用以展开或折叠子项目）。它们显示在表15.1中。 <span id="line-520" class="anchor"></span><span id="line-521" class="anchor"></span></p>
<p class="line867"><strong>表15.1</strong>  <strong>树控件中的按钮</strong> <span id="line-522" class="anchor"></span></p>
<div><table><tbody>
<tr>
<td><p class="line891"><tt>wx.TR_HAS_BUTTONS</tt> </p></td>
<td><p class="line862">按钮。在<tt>Windows</tt>上，+用于标明项目可以被展开，-表示可以折叠。 </p></td>
</tr>
<tr>
<td>
<span id="line-523" class="anchor"></span><p class="line891"><tt>wx.TR_NO_BUTTONS</tt> </p>
</td>
<td><p class="line862">没有按钮。 </p></td>
</tr>
</tbody></table></div>
<span id="line-524" class="anchor"></span><span id="line-525" class="anchor"></span><span id="line-526" class="anchor"></span><p class="line874">接下来的一类显示在表15.2中，它们决定树控件将连接线绘制在何处。 <span id="line-527" class="anchor"></span><span id="line-528" class="anchor"></span></p>
<p class="line867"><strong>表15.2</strong>  <strong>树控件中的连接线</strong> <span id="line-529" class="anchor"></span></p>
<div><table><tbody>
<tr>
<td><p class="line891"><tt>wx.TR_LINES_AT_ROOT</tt> </p></td>
<td><p class="line862">如果设置了这个样式，那么树控件将在多个<tt>root</tt>项目之间绘制连线。注意，如果<tt>wx.TR_HIDE_ROOT</tt>被设置了，那么你就有多个<tt>root</tt>项目。 </p></td>
</tr>
<tr>
<td>
<span id="line-530" class="anchor"></span><p class="line891"><tt>wx.TR_NO_LINES</tt> </p>
</td>
<td><p class="line862">如果设置了这个样式，那么树控件将不在兄弟项目间绘制连接线。这个样式将代替<tt>wx.TR_LINES_AT_ROOT</tt>。 </p></td>
</tr>
<tr>
<td>
<span id="line-531" class="anchor"></span><p class="line891"><tt>wx.TR_ROW_LINES </tt> </p>
</td>
<td><p class="line862">树控件在行之间将绘制边距。 </p></td>
</tr>
</tbody></table></div>
<span id="line-532" class="anchor"></span><span id="line-533" class="anchor"></span><span id="line-534" class="anchor"></span><p class="line874">第三类样式显示在表15.3中，用于控制树控件的选择模式。 <span id="line-535" class="anchor"></span><span id="line-536" class="anchor"></span></p>
<p class="line867"><strong>表15.3</strong>  <strong>树控件的选择模式</strong> <span id="line-537" class="anchor"></span></p>
<div><table><tbody>
<tr>
<td><p class="line891"><tt>wx.TR_EXTENDED</tt> </p></td>
<td><p class="line862">可以选择多个不连续的项。不是对所有的系统有效。 </p></td>
</tr>
<tr>
<td>
<span id="line-538" class="anchor"></span><p class="line891"><tt>wx.TR_MULTIPLE</tt> </p>
</td>
<td><p class="line862">可以选择一块且仅一块连续的项。 </p></td>
</tr>
<tr>
<td>
<span id="line-539" class="anchor"></span><p class="line891"><tt>wx.TR_SINGLE</tt> </p>
</td>
<td><p class="line862">一次只能选择一个结点。这是默认模式。 </p></td>
</tr>
</tbody></table></div>
<span id="line-540" class="anchor"></span><span id="line-541" class="anchor"></span><span id="line-542" class="anchor"></span><p class="line874">表15.4显示了其它的一样可作用于树的显示的样式。 <span id="line-543" class="anchor"></span><span id="line-544" class="anchor"></span></p>
<p class="line867"><strong>表15.4</strong>  <strong>树的其它显示样式</strong> <span id="line-545" class="anchor"></span></p>
<div><table><tbody>
<tr>
<td><p class="line891"><tt>wx.TR_FULL_ROW_HIGHLIGHT</tt> </p></td>
<td><p class="line862">如果设置了这个样式，那么当被选择时，被选项的整个行将高亮显示。默认情况下，只是文本区高亮。在<tt>Windows</tt>上，该样式只在也设置<tt>wx.NO_LINES</tt>时有效。 </p></td>
</tr>
<tr>
<td>
<span id="line-546" class="anchor"></span><p class="line891"><tt>wx.TR_HAS_VARIABLE_ROW_HEIGHT</tt> </p>
</td>
<td><p class="line862">如果设置了这个样式，则行的高度将根据其中的图像和文本而不同。否则，所有的行将是同样的高度（取决于最高的行）。 </p></td>
</tr>
<tr>
<td>
<span id="line-547" class="anchor"></span><p class="line891"><tt>wx.TR_HIDE_ROOT</tt> </p>
</td>
<td><p class="line862">如果设置了这个样式，则通过<tt>AddRoot()</tt>确定的<tt>root</tt>元素将不被显示。此时该结节的所有子项就如同它们是<tt>root</tt>一样显示。这个样式用于让一个树具有多个<tt>root</tt>元素的外观。 </p></td>
</tr>
</tbody></table></div>
<span id="line-548" class="anchor"></span><span id="line-549" class="anchor"></span><span id="line-550" class="anchor"></span><p class="line862">最后，<tt>wx.TR_DEFAULT_STYLE</tt>让你的树显示出最接近当前操作系统本地控件的样式。在程序中，你可以使用<tt>SetWindowStyle(styles)</tt>来改变样式，其中参数<tt>styles</tt>是你想要的新样式。 <span id="line-551" class="anchor"></span><span id="line-552" class="anchor"></span></p>
<p class="line862">树形控件有几个方法可以用以改变它的显示特性。在这些方法中，参数<tt>item</tt>是你想要改变的项的<tt>wx.TreeItemId</tt>。你可以使用方法<tt>SetItemBackgroundColor(item, col)</tt>来设置项目的背景色，其中参数<tt>col</tt>是一个<tt>wx.Colour</tt>或其它能够转换为颜色的东西。你可以使用<tt>SetItemTextColour(item,col)</tt>来改变文本的颜色。你可以使用<tt>SetItemFont(item, font)</tt>来设置项目的显示字体，其中参数<tt>font</tt>是一个<tt>wx.Font</tt>实例。如果你只想显示文本为粗体，你可以使用方法<tt>SetItemBold(item,
bold=True)</tt>，其中参数<tt>bold</tt>是一个布尔值，它决定是否显示为粗体。上面的四个<tt>set</tt>*方法都有对应的<tt>get</tt>*方法，如下所示： <tt>GetItemBackgroundColor(item), GetItemTextColour(item), GetItemFont(item), </tt>和<tt>IsBold(item)</tt>。其中的<tt>item</tt>参数是一个<tt>wx.TreeItemId</tt>。 <span id="line-553" class="anchor"></span><span id="line-554" class="anchor"></span></p>
<p class="line867">
</p>
<h2 id="head-be73c25b7cf42fc26752e9c6e5ce22871618006e">1.3. 对树形控件的元素排序</h2>
<span id="line-555" class="anchor"></span><p class="line862">对树形控件的元素排序的基本机制是方法<tt>SortChildren(item)</tt>。其中参数<tt>item</tt>是<tt>wx.TreeItemId</tt>的一个实例。该方法对此项目的子项目按显示字符串的字母的顺序进行排序。 <span id="line-556" class="anchor"></span><span id="line-557" class="anchor"></span></p>
<p class="line862">对于树的排序，每个树项目都需要有已分派的数据，不管你是否使用默认排序。在默认情况中，所指派的数据是<tt>None</tt>，但是对于排序任务，在树控件中你还是需要显式地设置。 <span id="line-558" class="anchor"></span><span id="line-559" class="anchor"></span></p>
<p class="line862">在15.1节，我们提及到了让你能够创建一个树项目及将该项目与一个任意数据对象相关联的方法。我们也告诉你不要使用这个机制。数据项目是一个<tt>wx.TreeItemData</tt>。在<tt>wxPython</tt>中在一预定义的快捷的方法，使你能够用以将一个<tt>Python</tt>对象与一个树项目关联起来。 <span id="line-560" class="anchor"></span><span id="line-561" class="anchor"></span></p>
<p class="line862">快捷的<tt>set</tt>*方法是<tt>SetItemPyData(item,
obj)</tt>。其中参数<tt>item</tt>是一个<tt>wx.TreeItemId</tt>，参数<tt>obj</tt>是一个任意的<tt>Python</tt>对象，<tt>wxPython</tt>在后台管理这个关联。当你想得到这个数据项时，你可以调用<tt>GetItemPyData(item)</tt>，它返回相关的<tt>Python</tt>对象。 <span id="line-562" class="anchor"></span><span id="line-563" class="anchor"></span></p>
<p class="line862">注意：对于<tt>wx.TreeItemData</tt>有一个特别的构造函数：<tt>wx.TreeItemData(obj)</tt>，其中参数<tt>obj</tt>是一个<tt>Python</tt>对象。因此你可以使用<tt>GetItemData(item)</tt>和<tt>SetItemData(item, obj)</tt>方法来处理这个<tt>Python</tt>数据。这是 <tt>SetItemPyData()</tt>方法的后台机制。这一信息在某些时候可能对你是有用的，但是大部分时候，你还是应该使用<tt>SetItemPyData(item, obj)</tt>和<tt>GetItemPyData(item)</tt>方法。 <span id="line-564" class="anchor"></span><span id="line-565" class="anchor"></span></p>
<p class="line862">要使用关联的数据来排序你的树，你的树必须是一个<tt>wx.TreeCtrl</tt>的自定义的子类，并且你必须覆盖<tt>OnCompareItems(item1, item2)</tt>方法。其中参数<tt>item1, item2</tt>是要比较的两个项的<tt>wx.TreeItemId</tt>实例。如果<tt>item1</tt>应该排在<tt>item2</tt>的前面，则方法返回-1，如果<tt>item1</tt>应该排在<tt>item2</tt>的后面，则返回1，相等则返回0。该方法是在当树控件为了排序而比较计算每个项时自动被调用的。你可以在<tt>OnCompareItems()</tt>方法中做你想做的事情。尤其是，你可以如下调用<tt>GetItemPyData()</tt>方法： <span id="line-566" class="anchor"></span><span id="line-567" class="anchor"></span></p>
<p class="line867"><span id="line-568" class="anchor"></span><span id="line-569" class="anchor"></span><span id="line-570" class="anchor"></span><span id="line-571" class="anchor"></span><span id="line-572" class="anchor"></span><span id="line-573" class="anchor"></span></p>
<div lang="en" dir="ltr" class="codearea">
<script type="text/javascript">
document.write('<a href="#" onclick="return togglenumber(\'CA-cc57165cfdadab8ac10f0c37e999a5359a719108_004\', 1, 1);" \
class="codenumbers">切换行号显示<\/a>');
</script><a class="codenumbers" onclick="return togglenumber('CA-cc57165cfdadab8ac10f0c37e999a5359a719108_004', 1, 1);" href="#">切换行号显示</a>
<pre lang="en" id="CA-cc57165cfdadab8ac10f0c37e999a5359a719108_004" dir="ltr"><span class="line"><span class="LineNumber">   1 </span><span class="ResWord">def</span> <span class="ID">OnCompareItems</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">item1</span><span class="Operator">,</span> <span class="ID">item2</span><span class="Operator">)</span><span class="Operator">;</span></span>
<span class="line"><span class="LineNumber">   2 </span>    <span class="ID">data1</span> <span class="Operator">=</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">GetItemPyData</span><span class="Operator">(</span><span class="ID">item1</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">   3 </span>    <span class="ID">data2</span> <span class="Operator">=</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">GetItemPyData</span><span class="Operator">(</span><span class="ID">item2</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">   4 </span>    <span class="ResWord">return</span> <span class="ID">cmp</span><span class="Operator">(</span><span class="ID">data1</span><span class="Operator">,</span> <span class="ID">data2</span><span class="Operator">)</span><span class="Text"></span></span>
</pre>
</div>
<span id="line-574" class="anchor"></span><p class="line867">
</p>
<h2 id="head-ebe94ef57fa789a002cd54e6705f1910aa23b28e">1.4. 控制与每项相关的图像</h2>
<span id="line-575" class="anchor"></span><p class="line862">用于树形控件的图像是由一个图像列表来维护的，这非常类似于列表控件中的图像维护。有关创建图像列表的细节，参见13章。一旦你创建了图像列表，你就可以使用<tt>SetImageList(imageList)</tt>或<tt>AssignImageList(imageList)</tt>方法把它分配给树控件。前者使得图像列表可以被其它控件共享，后者的图像列表所有权属于树控件。之后，你可能使用方法<tt>GetImageList()</tt>来得到该图像列表。图15.2显示了一个带有一些图像的树。 <span id="line-576" class="anchor"></span><span id="line-577" class="anchor"></span></p>
<p class="line867"><strong>图15.2</strong> <span id="line-578" class="anchor"></span><span id="line-579" class="anchor"></span></p>
<p class="line867"><img title="attachment:w15.2.gif" src="/moin/WxPythonInAction/ChapterFifteen?action=AttachFile&amp;do=get&amp;target=w15.2.gif" class="attachment"><span id="line-580" class="anchor"></span><span id="line-581" class="anchor"></span></p>
<p class="line862">例15.2是产生图15.2的代码。它使用了<tt>ArtProvider</tt>对象来提供图像。 <span id="line-582" class="anchor"></span><span id="line-583" class="anchor"></span></p>
<p class="line867"><strong>例15.2</strong>  <strong>一个带有图标的树控件</strong> <span id="line-584" class="anchor"></span><span id="line-585" class="anchor"></span></p>
<p class="line867"><span id="line-586" class="anchor"></span><span id="line-587" class="anchor"></span><span id="line-588" class="anchor"></span><span id="line-589" class="anchor"></span><span id="line-590" class="anchor"></span><span id="line-591" class="anchor"></span><span id="line-592" class="anchor"></span><span id="line-593" class="anchor"></span><span id="line-594" class="anchor"></span><span id="line-595" class="anchor"></span><span id="line-596" class="anchor"></span><span id="line-597" class="anchor"></span><span id="line-598" class="anchor"></span><span id="line-599" class="anchor"></span><span id="line-600" class="anchor"></span><span id="line-601" class="anchor"></span><span id="line-602" class="anchor"></span><span id="line-603" class="anchor"></span><span id="line-604" class="anchor"></span><span id="line-605" class="anchor"></span><span id="line-606" class="anchor"></span><span id="line-607" class="anchor"></span><span id="line-608" class="anchor"></span><span id="line-609" class="anchor"></span><span id="line-610" class="anchor"></span><span id="line-611" class="anchor"></span><span id="line-612" class="anchor"></span><span id="line-613" class="anchor"></span><span id="line-614" class="anchor"></span><span id="line-615" class="anchor"></span><span id="line-616" class="anchor"></span><span id="line-617" class="anchor"></span><span id="line-618" class="anchor"></span><span id="line-619" class="anchor"></span><span id="line-620" class="anchor"></span><span id="line-621" class="anchor"></span><span id="line-622" class="anchor"></span><span id="line-623" class="anchor"></span><span id="line-624" class="anchor"></span><span id="line-625" class="anchor"></span><span id="line-626" class="anchor"></span><span id="line-627" class="anchor"></span><span id="line-628" class="anchor"></span><span id="line-629" class="anchor"></span><span id="line-630" class="anchor"></span><span id="line-631" class="anchor"></span><span id="line-632" class="anchor"></span><span id="line-633" class="anchor"></span><span id="line-634" class="anchor"></span><span id="line-635" class="anchor"></span><span id="line-636" class="anchor"></span><span id="line-637" class="anchor"></span><span id="line-638" class="anchor"></span><span id="line-639" class="anchor"></span><span id="line-640" class="anchor"></span><span id="line-641" class="anchor"></span><span id="line-642" class="anchor"></span><span id="line-643" class="anchor"></span><span id="line-644" class="anchor"></span><span id="line-645" class="anchor"></span></p>
<div lang="en" dir="ltr" class="codearea">
<script type="text/javascript">
document.write('<a href="#" onclick="return togglenumber(\'CA-096793653502502b35b2f158fd22747a6bb9485a_005\', 1, 1);" \
class="codenumbers">切换行号显示<\/a>');
</script><a class="codenumbers" onclick="return togglenumber('CA-096793653502502b35b2f158fd22747a6bb9485a_005', 1, 1);" href="#">切换行号显示</a>
<pre lang="en" id="CA-096793653502502b35b2f158fd22747a6bb9485a_005" dir="ltr"><span class="line"><span class="LineNumber">   1 </span><span class="Comment">#-*- encoding:UTF-8 -*-</span></span>
<span class="line"><span class="LineNumber">   2 </span><span class="Comment"></span><span class="ResWord">import</span> <span class="ID">wx</span></span>
<span class="line"><span class="LineNumber">   3 </span><span class="ResWord">import</span> <span class="ID">data</span></span>
<span class="line"><span class="LineNumber">   4 </span><span class="ResWord">class</span> <span class="ID">TestFrame</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">Frame</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">   5 </span>    <span class="ResWord">def</span> <span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">   6 </span>        <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Frame</span><span class="Operator">.</span><span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">None</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">   7 </span>                <span class="ID">title</span><span class="Operator">=</span><span class="String">"simple tree with icons"</span><span class="Operator">,</span> <span class="ID">size</span><span class="Operator">=</span><span class="Operator">(</span><span class="Number">400</span><span class="Operator">,</span><span class="Number">500</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">   8 </span>        <span class="Comment"># 创建一个图像列表</span></span>
<span class="line"><span class="LineNumber">   9 </span><span class="Comment"></span>        <span class="ID">il</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">ImageList</span><span class="Operator">(</span><span class="Number">16</span><span class="Operator">,</span><span class="Number">16</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  10 </span>        <span class="Comment"># 添加图像到列表</span></span>
<span class="line"><span class="LineNumber">  11 </span><span class="Comment"></span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">fldridx</span> <span class="Operator">=</span> <span class="ID">il</span><span class="Operator">.</span><span class="ID">Add</span><span class="Operator">(</span></span>
<span class="line"><span class="LineNumber">  12 </span>            <span class="ID">wx</span><span class="Operator">.</span><span class="ID">ArtProvider</span><span class="Operator">.</span><span class="ID">GetBitmap</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">ART_FOLDER</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">  13 </span>                    <span class="ID">wx</span><span class="Operator">.</span><span class="ID">ART_OTHER</span><span class="Operator">,</span> <span class="Operator">(</span><span class="Number">16</span><span class="Operator">,</span><span class="Number">16</span><span class="Operator">)</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  14 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">fldropenidx</span> <span class="Operator">=</span> <span class="ID">il</span><span class="Operator">.</span><span class="ID">Add</span><span class="Operator">(</span></span>
<span class="line"><span class="LineNumber">  15 </span>            <span class="ID">wx</span><span class="Operator">.</span><span class="ID">ArtProvider</span><span class="Operator">.</span><span class="ID">GetBitmap</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">ART_FILE_OPEN</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">  16 </span>                    <span class="ID">wx</span><span class="Operator">.</span><span class="ID">ART_OTHER</span><span class="Operator">,</span> <span class="Operator">(</span><span class="Number">16</span><span class="Operator">,</span><span class="Number">16</span><span class="Operator">)</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  17 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">fileidx</span> <span class="Operator">=</span> <span class="ID">il</span><span class="Operator">.</span><span class="ID">Add</span><span class="Operator">(</span></span>
<span class="line"><span class="LineNumber">  18 </span>            <span class="ID">wx</span><span class="Operator">.</span><span class="ID">ArtProvider</span><span class="Operator">.</span><span class="ID">GetBitmap</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">ART_NORMAL_FILE</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">  19 </span>                    <span class="ID">wx</span><span class="Operator">.</span><span class="ID">ART_OTHER</span><span class="Operator">,</span> <span class="Operator">(</span><span class="Number">16</span><span class="Operator">,</span><span class="Number">16</span><span class="Operator">)</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  20 </span></span>
<span class="line"><span class="LineNumber">  21 </span>        <span class="Comment"># 创建树</span></span>
<span class="line"><span class="LineNumber">  22 </span><span class="Comment"></span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">tree</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">TreeCtrl</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  23 </span>        <span class="Comment"># 给树分配图像列表</span></span>
<span class="line"><span class="LineNumber">  24 </span><span class="Comment"></span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">tree</span><span class="Operator">.</span><span class="ID">AssignImageList</span><span class="Operator">(</span><span class="ID">il</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  25 </span>        <span class="ID">root</span> <span class="Operator">=</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">tree</span><span class="Operator">.</span><span class="ID">AddRoot</span><span class="Operator">(</span><span class="String">"wx.Object"</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  26 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">tree</span><span class="Operator">.</span><span class="ID">SetItemImage</span><span class="Operator">(</span><span class="ID">root</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">fldridx</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">  27 </span>                               <span class="ID">wx</span><span class="Operator">.</span><span class="ID">TreeItemIcon_Normal</span><span class="Operator">)</span><span class="Comment"># 设置根的图像</span></span>
<span class="line"><span class="LineNumber">  28 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">tree</span><span class="Operator">.</span><span class="ID">SetItemImage</span><span class="Operator">(</span><span class="ID">root</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">fldropenidx</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">  29 </span>                               <span class="ID">wx</span><span class="Operator">.</span><span class="ID">TreeItemIcon_Expanded</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  30 </span></span>
<span class="line"><span class="LineNumber">  31 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">AddTreeNodes</span><span class="Operator">(</span><span class="ID">root</span><span class="Operator">,</span> <span class="ID">data</span><span class="Operator">.</span><span class="ID">tree</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  32 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">tree</span><span class="Operator">.</span><span class="ID">Expand</span><span class="Operator">(</span><span class="ID">root</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  33 </span></span>
<span class="line"><span class="LineNumber">  34 </span>    <span class="ResWord">def</span> <span class="ID">AddTreeNodes</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">parentItem</span><span class="Operator">,</span> <span class="ID">items</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  35 </span>        <span class="ResWord">for</span> <span class="ID">item</span> <span class="ResWord">in</span> <span class="ID">items</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  36 </span>            <span class="ResWord">if</span> <span class="ID">type</span><span class="Operator">(</span><span class="ID">item</span><span class="Operator">)</span> <span class="Operator">==</span> <span class="ID">str</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  37 </span>                <span class="ID">newItem</span> <span class="Operator">=</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">tree</span><span class="Operator">.</span><span class="ID">AppendItem</span><span class="Operator">(</span><span class="ID">parentItem</span><span class="Operator">,</span> <span class="ID">item</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  38 </span>                <span class="ID">self</span><span class="Operator">.</span><span class="ID">tree</span><span class="Operator">.</span><span class="ID">SetItemImage</span><span class="Operator">(</span><span class="ID">newItem</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">fileidx</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">  39 </span>                                       <span class="ID">wx</span><span class="Operator">.</span><span class="ID">TreeItemIcon_Normal</span><span class="Operator">)</span><span class="Comment"># 设置数据图像</span></span>
<span class="line"><span class="LineNumber">  40 </span>            <span class="ResWord">else</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  41 </span>                <span class="ID">newItem</span> <span class="Operator">=</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">tree</span><span class="Operator">.</span><span class="ID">AppendItem</span><span class="Operator">(</span><span class="ID">parentItem</span><span class="Operator">,</span> <span class="ID">item</span><span class="Operator">[</span><span class="Number">0</span><span class="Operator">]</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  42 </span>                <span class="ID">self</span><span class="Operator">.</span><span class="ID">tree</span><span class="Operator">.</span><span class="ID">SetItemImage</span><span class="Operator">(</span><span class="ID">newItem</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">fldridx</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">  43 </span>                                       <span class="ID">wx</span><span class="Operator">.</span><span class="ID">TreeItemIcon_Normal</span><span class="Operator">)</span><span class="Comment"># 设置结点的图像</span></span>
<span class="line"><span class="LineNumber">  44 </span>                <span class="ID">self</span><span class="Operator">.</span><span class="ID">tree</span><span class="Operator">.</span><span class="ID">SetItemImage</span><span class="Operator">(</span><span class="ID">newItem</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">fldropenidx</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">  45 </span>                                       <span class="ID">wx</span><span class="Operator">.</span><span class="ID">TreeItemIcon_Expanded</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  46 </span></span>
<span class="line"><span class="LineNumber">  47 </span>                <span class="ID">self</span><span class="Operator">.</span><span class="ID">AddTreeNodes</span><span class="Operator">(</span><span class="ID">newItem</span><span class="Operator">,</span> <span class="ID">item</span><span class="Operator">[</span><span class="Number">1</span><span class="Operator">]</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  48 </span></span>
<span class="line"><span class="LineNumber">  49 </span>    <span class="ResWord">def</span> <span class="ID">GetItemText</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">item</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  50 </span>        <span class="ResWord">if</span> <span class="ID">item</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  51 </span>            <span class="ResWord">return</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">tree</span><span class="Operator">.</span><span class="ID">GetItemText</span><span class="Operator">(</span><span class="ID">item</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  52 </span>        <span class="ResWord">else</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  53 </span>            <span class="ResWord">return</span> <span class="String">""</span></span>
<span class="line"><span class="LineNumber">  54 </span></span>
<span class="line"><span class="LineNumber">  55 </span><span class="ID">app</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">PySimpleApp</span><span class="Operator">(</span><span class="ID">redirect</span><span class="Operator">=</span><span class="ID">True</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  56 </span><span class="ID">frame</span> <span class="Operator">=</span> <span class="ID">TestFrame</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  57 </span><span class="ID">frame</span><span class="Operator">.</span><span class="ID">Show</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  58 </span><span class="ID">app</span><span class="Operator">.</span><span class="ID">MainLoop</span><span class="Operator">(</span><span class="Operator">)</span><span class="Text"></span></span>
</pre>
</div>
<span id="line-646" class="anchor"></span><p class="line862">如你所见，当你添加项目到列表中时，对于未选和选中状态，有两个不同的图像可用于分配给项目。和列表控件一样，你可以指定图像在图像列表中的索引。如果你想在项目被创建后得到所分配的图像，你可以使用方法<tt>GetItemImage(item,
which=wx.TreeItemIcon_Normal)</tt>。其中参数<tt>item</tt>是项目的<tt>wx.TreeItemId</tt>。参数<tt>which</tt>控制你将得到了是哪个图像，默认值<tt>wx.TreeItemIcon_Normal</tt>，将得到该项目的未选状态的图像的索引。<tt>which</tt>的另一个值<tt>wx.TreeItemIcon_Selected</tt>的使用，将返回选中状态的图像，<tt>wx.TreeItemIcon_Expanded</tt>和<tt>wxTreeItemIcon_SelectedExpanded</tt>返回当该树项目被展开时所使用的图像。注意，后者的两个图像不能使用添加方法来被设置——如果你想设置的话，你必须使用方法<tt>SetItemImage(item,
image,  which=wx.TreeItemIcon_Normal)</tt>来实现。其中参数<tt>item</tt>是<tt>wx.TreeItemId</tt>的实例，参数<tt>image</tt>是新图像的整数索引，参数<tt>which</tt>同<tt>get</tt>*方法。 <span id="line-647" class="anchor"></span><span id="line-648" class="anchor"></span></p>
<p class="line867">
</p>
<h2 id="head-d4a81cf7c36e00a95bc884fcab944faa5e592815">1.5. 使用编程的方式访问树。</h2>
<span id="line-649" class="anchor"></span><p class="line862">在15.1节中，我们谈到没有直接得到一个给定项目的子项目的<tt>Python</tt>列表的方法，至于一个特定子项目的索引就更不用说了。要实现这个，我们需要使用本节所说的遍历方法来访问树的结点。 <span id="line-650" class="anchor"></span><span id="line-651" class="anchor"></span></p>
<p class="line862">要开始遍历树，我们首先要使用<tt>GetRootItem()</tt>来得到根元素。该方法返回树的根元素的<tt>wx.TreeItemId</tt>。之后，你就可以使用诸如<tt>GetItemText()</tt>或<tt>GetItemPyData()</tt>之类的方法来获取关于根元素的更多的信息。 <span id="line-652" class="anchor"></span><span id="line-653" class="anchor"></span></p>
<p class="line862">一旦你得到了一个项目，你就可以通过迭代器来遍历子项目的列表。你可以使用方法<tt>GetFirstChild(item)</tt>来得到子树中的第一个孩子，该方法返回一个二元元组(<tt>child,
cookie)</tt>。参数<tt>item</tt>是第一个孩子的<tt>wx.TreeItemId</tt>。除了告诉你每一个孩子是什么外，该方法还初始化一个迭代对象，该对象使你能够遍历该树。<tt>cookie</tt>值只是一个标志，它使得树控件能够同时保持对多个迭代器的跟踪，而它们之间不会彼此干扰。 <span id="line-654" class="anchor"></span><span id="line-655" class="anchor"></span></p>
<p class="line862">一旦你由<tt>GetFirstChild()</tt>得到了<tt>cookie</tt>，你就可以通过反复调用<tt>GetNextChild(item,
cookie)</tt>来得到其余的孩子。这里的<tt>item</tt>父项的<tt>ID</tt>，<tt>cookie</tt>是由<tt>GetFirstChild()</tt>或前一个<tt>GetNextChild()</tt>调用返回的。<tt>GetNextChild()</tt>方法也返回一个二元元组(<tt>child, cookie)</tt>。如果此时没有下一个项目了，那么你就到达了孩子列表的末尾，系统将返回一个无效的孩子<tt>ID</tt>。你可以通过使用<tt>wx.TreeItemId.IsOk()</tt>或<tt>__nonzero__</tt>方法测试这种情况。下面的函数返回给定项目的所有孩子的文本的一个列表。 <span id="line-656" class="anchor"></span><span id="line-657" class="anchor"></span></p>
<p class="line867"><span id="line-658" class="anchor"></span><span id="line-659" class="anchor"></span><span id="line-660" class="anchor"></span><span id="line-661" class="anchor"></span><span id="line-662" class="anchor"></span><span id="line-663" class="anchor"></span><span id="line-664" class="anchor"></span><span id="line-665" class="anchor"></span><span id="line-666" class="anchor"></span></p>
<div lang="en" dir="ltr" class="codearea">
<script type="text/javascript">
document.write('<a href="#" onclick="return togglenumber(\'CA-5d6a6211b8c570551021f7c975b15e92fdd6e15d_006\', 1, 1);" \
class="codenumbers">切换行号显示<\/a>');
</script><a class="codenumbers" onclick="return togglenumber('CA-5d6a6211b8c570551021f7c975b15e92fdd6e15d_006', 1, 1);" href="#">切换行号显示</a>
<pre lang="en" id="CA-5d6a6211b8c570551021f7c975b15e92fdd6e15d_006" dir="ltr"><span class="line"><span class="LineNumber">   1 </span><span class="ResWord">def</span> <span class="ID">getChildren</span><span class="Operator">(</span><span class="ID">tree</span><span class="Operator">,</span> <span class="ID">parent</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">   2 </span>    <span class="ID">result</span> <span class="Operator">=</span> <span class="Operator">[</span><span class="Operator">]</span></span>
<span class="line"><span class="LineNumber">   3 </span>    <span class="ID">item</span><span class="Operator">,</span> <span class="ID">cookie</span> <span class="Operator">=</span> <span class="ID">tree</span><span class="Operator">.</span><span class="ID">GetFirstChild</span><span class="Operator">(</span><span class="ID">parent</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">   4 </span>    <span class="ResWord">while</span> <span class="ID">item</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">   5 </span>        <span class="ID">result</span><span class="Operator">.</span><span class="ID">append</span><span class="Operator">(</span><span class="ID">tree</span><span class="Operator">.</span><span class="ID">GetItemText</span><span class="Operator">(</span><span class="ID">item</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">   6 </span>    <span class="ID">item</span><span class="Operator">,</span> <span class="ID">cookie</span> <span class="Operator">=</span> <span class="ID">tree</span><span class="Operator">.</span><span class="ID">getNextChild</span><span class="Operator">(</span><span class="ID">parent</span><span class="Operator">,</span> <span class="ID">cookie</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">   7 </span>    <span class="ResWord">return</span> <span class="ID">result</span><span class="Text"></span></span>
</pre>
</div>
<span id="line-667" class="anchor"></span><p class="line862">这个函数得到给定父项目的第一个孩子，然后将第一个孩子的文本添加到列表中，然后通过循环来得到每个子项目的文本并添加到列表中，直到得到一个无效的项，这时就返回<tt>result</tt>。 <span id="line-668" class="anchor"></span><span id="line-669" class="anchor"></span></p>
<p class="line862">要得到父项目的最后一个孩子，你可以使用方法<tt>GetLastChild(item)</tt>，它返回列表中的最后的项目的<tt>wx.TreeItemId</tt>。由于这个方法不用于驱动迭代器来遍历整个孩子列表，所以它不需要<tt>cookie</tt>机制。如果你有这个最后的子项且你想得到它的父项，可以使用方法<tt>GetItemParent(item)</tt>来返回给定项的父项的<tt>ID</tt>。 <span id="line-670" class="anchor"></span><span id="line-671" class="anchor"></span></p>
<p class="line862">你可以使用方法<tt>GetNextSibling(item)</tt>和<tt>GetPrevSibling(item)</tt>来在同级的项目间前后访问。这些方法均返回相关项的<tt>wx.TreeItemId</tt>。由这些方法同样不用于驱动迭代器，所以它们都不需要一个<tt>cookie</tt>。当你已经到达列表的两头时，将没有下一项或前一项，那么这些方法将返回一个无效的项（例如：<tt>item.IsOk() == False</tt>）。 <span id="line-672" class="anchor"></span><span id="line-673" class="anchor"></span></p>
<p class="line862">要确定一个项是否有孩子，使用方法<tt>ItemHasChildren(item)</tt>，该方法返回布尔值<tt>True</tt>或<tt>False</tt>。你可以使用方法<tt>SetItemHasChildren(item, hasChildren=True)</tt>来将一个项设置为有子项，如果这样，即使该项没有实际的子项，它也将显示得与有子项的一样。也就是说该项旁边会有一个扩展或折叠的按钮，以便展开或折叠。这通常被用于实现一个虚的树控件。这个技术将在15.7节中演示。 <span id="line-674" class="anchor"></span><span id="line-675" class="anchor"></span></p>
<p class="line867">
</p>
<h2 id="head-cdad4c7bb4b316abf54384f1f4cb3a0dbaab64bd">1.6. 管理树中的选择</h2>
<span id="line-676" class="anchor"></span><p class="line862">树形控件允许你通过程序的方式管理树中的被选项。基本的方法是<tt>SelectItem(item,select=True)
</tt>。在单选树控件中，该方法将选择指定项<tt>item</tt>（<tt>wx.TreeItemId</tt>），同时自动撤消对先前选项的选择。如果参数<tt>select</tt>的取值是<tt>False</tt>，那么该方法将取消对参数<tt>item</tt>代表的项的选择。在一个可多选的树控件中，<tt>SelectItem()</tt>方法只改变<tt>item</tt>所代表的项的状态，而不改变树中其它项的选择状态。在可多选的树中，你也可以使用方法<tt>ToggleItemSelection(item)</tt>，它只切换参数<tt>item</tt>所代表项的选择状态。 <span id="line-677" class="anchor"></span><span id="line-678" class="anchor"></span></p>
<p class="line862">对于取消选择还有三个快捷的方法。方法<tt>Unselect()</tt>取消单选模式树中的当前被选项的选择。在多选模式树中，使用<tt>UnselectAll()</tt>来取消所有的选择。如果你只想取消在一个多选树中的一个项的被选状态，可以使用方法<tt>UnselectItem(item)</tt>。 <span id="line-679" class="anchor"></span><span id="line-680" class="anchor"></span></p>
<p class="line862">你也可以使用方法<tt>IsSelected(item)</tt>来查询一个项目的选择状态，该方法返回布尔值<tt>True</tt>或<tt>False</tt>。对于单选树，你可能使用方法<tt>GetSelection()</tt>来得到当前被选项目的<tt>wx.TreeItemId</tt>。对于多选树，可以使用方法<tt>GetSelections()</tt>来得到所有被选项的<tt>wx.TreeItemId</tt>的一个<tt>Python</tt>列表。 <span id="line-681" class="anchor"></span><span id="line-682" class="anchor"></span></p>
<p class="line862">当树控件中发生选择变化的时候，有两个事件将被触发并可被捕获。第一个事件是<tt>wx.EVT_TREE_SEL_CHANGING,</tt>它在被选项实际改变之前发生。如果你要处理这个事件，你可以使用事件的<tt>Veto()</tt>方法来阻止选择的改变。在选择已经改变之后，事件<tt>wx.EVT_TREE_SEL_CHANGED</tt>被触发。这两个事件的类是<tt>wx.TreeEvent</tt>，这将在15.8节中作更完整的讨论。 <span id="line-683" class="anchor"></span><span id="line-684" class="anchor"></span></p>
<p class="line867">
</p>
<h2 id="head-4ac24c1e78d471bfdec42109d600b2041482872f">1.7. 控制项目的可见性</h2>
<span id="line-685" class="anchor"></span><p class="line862">在树控件中有两种机制可以让你用编程的方式控制某项目的可见性。你可以使用方法<tt>Collapse(item)</tt>和<tt>Expand(item)</tt>指定给定的树项目是展开的或折叠的。这些方法改变树控件的显示，并且如果对一个没有子项的项目调用该方法将不起作用。这儿还有一个方便的函数：<tt>CollapseAndReset(item)</tt>，该方法折叠指定的项，并删除指定项的所有孩子。另外，方法<tt>Toggle(item)</tt>用于切换项目的展开和折叠状态。你可以使用方法<tt>IsExpanded(item)</tt>来查询项目的当前展开状态。 <span id="line-686" class="anchor"></span><span id="line-687" class="anchor"></span></p>
<p class="line862">展开或折叠一个树项目触发两事件。在展开或折叠前，事件<tt>wx.EVT_TREE_ITEM_COLLAPSING </tt>或<tt>wx.EVT_TREE_ITEM_EXPANDING</tt>被触发。在你的处理方法中，你可以使用事件的<tt>Veto()</tt>方法来阻止展开或折叠。在展开或折叠发生后，事件<tt>EVT_TREE_ITEM_COLLAPSED</tt>或<tt>wx.EVT_TREE_ITEM_EXPANDED</tt>被触发。这四个事件都是类<tt>wx.TreeEvent</tt>的事件类型。 <span id="line-688" class="anchor"></span><span id="line-689" class="anchor"></span></p>
<p class="line867"><strong>虚树</strong> <span id="line-690" class="anchor"></span><span id="line-691" class="anchor"></span></p>
<p class="line874">展开和折叠项目的一个令人感兴趣的的用法是创建一个虚树，新项目仅当父项展开时添加。例15.3显示这样一个样列。 <span id="line-692" class="anchor"></span><span id="line-693" class="anchor"></span></p>
<p class="line867"><strong>例15.3</strong>  <strong>展开时动态添加新的项目</strong> <span id="line-694" class="anchor"></span><span id="line-695" class="anchor"></span></p>
<p class="line867"><span id="line-696" class="anchor"></span><span id="line-697" class="anchor"></span><span id="line-698" class="anchor"></span><span id="line-699" class="anchor"></span><span id="line-700" class="anchor"></span><span id="line-701" class="anchor"></span><span id="line-702" class="anchor"></span><span id="line-703" class="anchor"></span><span id="line-704" class="anchor"></span><span id="line-705" class="anchor"></span><span id="line-706" class="anchor"></span><span id="line-707" class="anchor"></span><span id="line-708" class="anchor"></span><span id="line-709" class="anchor"></span><span id="line-710" class="anchor"></span><span id="line-711" class="anchor"></span><span id="line-712" class="anchor"></span><span id="line-713" class="anchor"></span><span id="line-714" class="anchor"></span><span id="line-715" class="anchor"></span><span id="line-716" class="anchor"></span><span id="line-717" class="anchor"></span><span id="line-718" class="anchor"></span><span id="line-719" class="anchor"></span><span id="line-720" class="anchor"></span><span id="line-721" class="anchor"></span><span id="line-722" class="anchor"></span><span id="line-723" class="anchor"></span><span id="line-724" class="anchor"></span><span id="line-725" class="anchor"></span><span id="line-726" class="anchor"></span><span id="line-727" class="anchor"></span><span id="line-728" class="anchor"></span><span id="line-729" class="anchor"></span><span id="line-730" class="anchor"></span><span id="line-731" class="anchor"></span><span id="line-732" class="anchor"></span><span id="line-733" class="anchor"></span><span id="line-734" class="anchor"></span><span id="line-735" class="anchor"></span><span id="line-736" class="anchor"></span><span id="line-737" class="anchor"></span><span id="line-738" class="anchor"></span><span id="line-739" class="anchor"></span><span id="line-740" class="anchor"></span><span id="line-741" class="anchor"></span><span id="line-742" class="anchor"></span><span id="line-743" class="anchor"></span><span id="line-744" class="anchor"></span><span id="line-745" class="anchor"></span><span id="line-746" class="anchor"></span><span id="line-747" class="anchor"></span><span id="line-748" class="anchor"></span><span id="line-749" class="anchor"></span><span id="line-750" class="anchor"></span><span id="line-751" class="anchor"></span><span id="line-752" class="anchor"></span><span id="line-753" class="anchor"></span><span id="line-754" class="anchor"></span><span id="line-755" class="anchor"></span><span id="line-756" class="anchor"></span><span id="line-757" class="anchor"></span><span id="line-758" class="anchor"></span><span id="line-759" class="anchor"></span><span id="line-760" class="anchor"></span><span id="line-761" class="anchor"></span><span id="line-762" class="anchor"></span><span id="line-763" class="anchor"></span><span id="line-764" class="anchor"></span><span id="line-765" class="anchor"></span><span id="line-766" class="anchor"></span><span id="line-767" class="anchor"></span><span id="line-768" class="anchor"></span><span id="line-769" class="anchor"></span><span id="line-770" class="anchor"></span><span id="line-771" class="anchor"></span><span id="line-772" class="anchor"></span><span id="line-773" class="anchor"></span><span id="line-774" class="anchor"></span><span id="line-775" class="anchor"></span><span id="line-776" class="anchor"></span><span id="line-777" class="anchor"></span><span id="line-778" class="anchor"></span><span id="line-779" class="anchor"></span><span id="line-780" class="anchor"></span><span id="line-781" class="anchor"></span></p>
<div lang="en" dir="ltr" class="codearea">
<script type="text/javascript">
document.write('<a href="#" onclick="return togglenumber(\'CA-2b5f0ab153cc76b30b9bde081680ddb2f9197294_007\', 1, 1);" \
class="codenumbers">切换行号显示<\/a>');
</script><a class="codenumbers" onclick="return togglenumber('CA-2b5f0ab153cc76b30b9bde081680ddb2f9197294_007', 1, 1);" href="#">切换行号显示</a>
<pre lang="en" id="CA-2b5f0ab153cc76b30b9bde081680ddb2f9197294_007" dir="ltr"><span class="line"><span class="LineNumber">   1 </span><span class="Comment">#-*- encoding:UTF-8 -*-</span></span>
<span class="line"><span class="LineNumber">   2 </span><span class="Comment"></span><span class="ResWord">import</span> <span class="ID">wx</span></span>
<span class="line"><span class="LineNumber">   3 </span><span class="ResWord">import</span> <span class="ID">data</span></span>
<span class="line"><span class="LineNumber">   4 </span><span class="ResWord">class</span> <span class="ID">TestFrame</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">Frame</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">   5 </span>    <span class="ResWord">def</span> <span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">   6 </span>        <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Frame</span><span class="Operator">.</span><span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">None</span><span class="Operator">,</span> <span class="ID">title</span><span class="Operator">=</span><span class="String">"virtual tree with
icons"</span><span class="Operator">,</span> <span class="ID">size</span><span class="Operator">=</span><span class="Operator">(</span><span class="Number">400</span><span class="Operator">,</span><span class="Number">500</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">   7 </span>        <span class="ID">il</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">ImageList</span><span class="Operator">(</span><span class="Number">16</span><span class="Operator">,</span><span class="Number">16</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">   8 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">fldridx</span> <span class="Operator">=</span> <span class="ID">il</span><span class="Operator">.</span><span class="ID">Add</span><span class="Operator">(</span></span>
<span class="line"><span class="LineNumber">   9 </span>            <span class="ID">wx</span><span class="Operator">.</span><span class="ID">ArtProvider</span><span class="Operator">.</span><span class="ID">GetBitmap</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">ART_FOLDER</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">ART_OTHER</span><span class="Operator">,</span> <span class="Operator">(</span><span class="Number">16</span><span class="Operator">,</span><span class="Number">16</span><span class="Operator">)</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  10 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">fldropenidx</span> <span class="Operator">=</span> <span class="ID">il</span><span class="Operator">.</span><span class="ID">Add</span><span class="Operator">(</span></span>
<span class="line"><span class="LineNumber">  11 </span>            <span class="ID">wx</span><span class="Operator">.</span><span class="ID">ArtProvider</span><span class="Operator">.</span><span class="ID">GetBitmap</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">ART_FILE_OPEN</span><span class="Operator">,</span>   <span class="ID">wx</span><span class="Operator">.</span><span class="ID">ART_OTHER</span><span class="Operator">,</span> <span class="Operator">(</span><span class="Number">16</span><span class="Operator">,</span><span class="Number">16</span><span class="Operator">)</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  12 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">fileidx</span> <span class="Operator">=</span> <span class="ID">il</span><span class="Operator">.</span><span class="ID">Add</span><span class="Operator">(</span></span>
<span class="line"><span class="LineNumber">  13 </span>            <span class="ID">wx</span><span class="Operator">.</span><span class="ID">ArtProvider</span><span class="Operator">.</span><span class="ID">GetBitmap</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">ART_NORMAL_FILE</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">ART_OTHER</span><span class="Operator">,</span> <span class="Operator">(</span><span class="Number">16</span><span class="Operator">,</span><span class="Number">16</span><span class="Operator">)</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  14 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">tree</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">TreeCtrl</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  15 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">tree</span><span class="Operator">.</span><span class="ID">AssignImageList</span><span class="Operator">(</span><span class="ID">il</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  16 </span>        <span class="ID">root</span> <span class="Operator">=</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">tree</span><span class="Operator">.</span><span class="ID">AddRoot</span><span class="Operator">(</span><span class="String">"wx.Object"</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  17 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">tree</span><span class="Operator">.</span><span class="ID">SetItemImage</span><span class="Operator">(</span><span class="ID">root</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">fldridx</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">  18 </span>                               <span class="ID">wx</span><span class="Operator">.</span><span class="ID">TreeItemIcon_Normal</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  19 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">tree</span><span class="Operator">.</span><span class="ID">SetItemImage</span><span class="Operator">(</span><span class="ID">root</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">fldropenidx</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">  20 </span>                               <span class="ID">wx</span><span class="Operator">.</span><span class="ID">TreeItemIcon_Expanded</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  21 </span></span>
<span class="line"><span class="LineNumber">  22 </span>        <span class="Comment"># Instead of adding nodes for the whole tree, just attach some</span></span>
<span class="line"><span class="LineNumber">  23 </span><span class="Comment"></span>        <span class="Comment"># data to the root node so that it can find and add its child</span></span>
<span class="line"><span class="LineNumber">  24 </span><span class="Comment"></span>        <span class="Comment"># nodes when it is expanded, and mark it as having children so</span></span>
<span class="line"><span class="LineNumber">  25 </span><span class="Comment"></span>        <span class="Comment"># it will be expandable.</span></span>
<span class="line"><span class="LineNumber">  26 </span><span class="Comment"></span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">tree</span><span class="Operator">.</span><span class="ID">SetItemPyData</span><span class="Operator">(</span><span class="ID">root</span><span class="Operator">,</span> <span class="ID">data</span><span class="Operator">.</span><span class="ID">tree</span><span class="Operator">)</span><span class="Comment">#创建一个根</span></span>
<span class="line"><span class="LineNumber">  27 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">tree</span><span class="Operator">.</span><span class="ID">SetItemHasChildren</span><span class="Operator">(</span><span class="ID">root</span><span class="Operator">,</span> <span class="ID">True</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  28 </span></span>
<span class="line"><span class="LineNumber">  29 </span>        <span class="Comment"># Bind some interesting events</span></span>
<span class="line"><span class="LineNumber">  30 </span><span class="Comment"></span><span class="Comment"># 绑定事件</span></span>
<span class="line"><span class="LineNumber">  31 </span><span class="Comment"></span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Bind</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_TREE_ITEM_EXPANDED</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">OnItemExpanded</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">tree</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  32 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Bind</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_TREE_ITEM_COLLAPSED</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">OnItemCollapsed</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">tree</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  33 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Bind</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_TREE_SEL_CHANGED</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">OnSelChanged</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">tree</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  34 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Bind</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_TREE_ITEM_ACTIVATED</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">OnActivated</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">tree</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  35 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Bind</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_TREE_ITEM_EXPANDING</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">OnItemExpanding</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">tree</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  36 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">tree</span><span class="Operator">.</span><span class="ID">Expand</span><span class="Operator">(</span><span class="ID">root</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  37 </span></span>
<span class="line"><span class="LineNumber">  38 </span>    <span class="ResWord">def</span> <span class="ID">AddTreeNodes</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">parentItem</span><span class="Operator">)</span><span class="Operator">:</span><span class="Comment">#给父项目添加结节</span></span>
<span class="line"><span class="LineNumber">  39 </span>        <span class="String">"""</span></span>
<span class="line"><span class="LineNumber">  40 </span><span class="String">        Add nodes for just the children of the parentItem</span></span>
<span class="line"><span class="LineNumber">  41 </span><span class="String">        """</span></span>
<span class="line"><span class="LineNumber">  42 </span>        <span class="ID">items</span> <span class="Operator">=</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">tree</span><span class="Operator">.</span><span class="ID">GetItemPyData</span><span class="Operator">(</span><span class="ID">parentItem</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  43 </span>        <span class="ResWord">for</span> <span class="ID">item</span> <span class="ResWord">in</span> <span class="ID">items</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  44 </span>            <span class="ResWord">if</span> <span class="ID">type</span><span class="Operator">(</span><span class="ID">item</span><span class="Operator">)</span> <span class="Operator">==</span> <span class="ID">str</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  45 </span>                <span class="Comment"># a leaf node</span></span>
<span class="line"><span class="LineNumber">  46 </span><span class="Comment"></span>                <span class="ID">newItem</span> <span class="Operator">=</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">tree</span><span class="Operator">.</span><span class="ID">AppendItem</span><span class="Operator">(</span><span class="ID">parentItem</span><span class="Operator">,</span> <span class="ID">item</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  47 </span>                <span class="ID">self</span><span class="Operator">.</span><span class="ID">tree</span><span class="Operator">.</span><span class="ID">SetItemImage</span><span class="Operator">(</span><span class="ID">newItem</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">fileidx</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">  48 </span>                                       <span class="ID">wx</span><span class="Operator">.</span><span class="ID">TreeItemIcon_Normal</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  49 </span>            <span class="ResWord">else</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  50 </span>                <span class="Comment"># this item has children</span></span>
<span class="line"><span class="LineNumber">  51 </span><span class="Comment"></span>                <span class="ID">newItem</span> <span class="Operator">=</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">tree</span><span class="Operator">.</span><span class="ID">AppendItem</span><span class="Operator">(</span><span class="ID">parentItem</span><span class="Operator">,</span> <span class="ID">item</span><span class="Operator">[</span><span class="Number">0</span><span class="Operator">]</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  52 </span>                <span class="ID">self</span><span class="Operator">.</span><span class="ID">tree</span><span class="Operator">.</span><span class="ID">SetItemImage</span><span class="Operator">(</span><span class="ID">newItem</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">fldridx</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">  53 </span>                                       <span class="ID">wx</span><span class="Operator">.</span><span class="ID">TreeItemIcon_Normal</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  54 </span>                <span class="ID">self</span><span class="Operator">.</span><span class="ID">tree</span><span class="Operator">.</span><span class="ID">SetItemImage</span><span class="Operator">(</span><span class="ID">newItem</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">fldropenidx</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">  55 </span>                                       <span class="ID">wx</span><span class="Operator">.</span><span class="ID">TreeItemIcon_Expanded</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  56 </span>                <span class="ID">self</span><span class="Operator">.</span><span class="ID">tree</span><span class="Operator">.</span><span class="ID">SetItemPyData</span><span class="Operator">(</span><span class="ID">newItem</span><span class="Operator">,</span> <span class="ID">item</span><span class="Operator">[</span><span class="Number">1</span><span class="Operator">]</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  57 </span>                <span class="ID">self</span><span class="Operator">.</span><span class="ID">tree</span><span class="Operator">.</span><span class="ID">SetItemHasChildren</span><span class="Operator">(</span><span class="ID">newItem</span><span class="Operator">,</span> <span class="ID">True</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  58 </span></span>
<span class="line"><span class="LineNumber">  59 </span></span>
<span class="line"><span class="LineNumber">  60 </span>    <span class="ResWord">def</span> <span class="ID">GetItemText</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">item</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  61 </span>        <span class="ResWord">if</span> <span class="ID">item</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  62 </span>            <span class="ResWord">return</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">tree</span><span class="Operator">.</span><span class="ID">GetItemText</span><span class="Operator">(</span><span class="ID">item</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  63 </span>        <span class="ResWord">else</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  64 </span>            <span class="ResWord">return</span> <span class="String">""</span></span>
<span class="line"><span class="LineNumber">  65 </span></span>
<span class="line"><span class="LineNumber">  66 </span>    <span class="ResWord">def</span> <span class="ID">OnItemExpanded</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">evt</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  67 </span>        <span class="ResWord">print</span> <span class="String">"OnItemExpanded: "</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">GetItemText</span><span class="Operator">(</span><span class="ID">evt</span><span class="Operator">.</span><span class="ID">GetItem</span><span class="Operator">(</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  68 </span>    <span class="ResWord">def</span> <span class="ID">OnItemExpanding</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">evt</span><span class="Operator">)</span><span class="Operator">:</span><span class="Comment">#当展开时创建结点</span></span>
<span class="line"><span class="LineNumber">  69 </span>        <span class="Comment"># When the item is about to be expanded add the first level of child nodes</span></span>
<span class="line"><span class="LineNumber">  70 </span><span class="Comment"></span>        <span class="ResWord">print</span> <span class="String">"OnItemExpanding:"</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">GetItemText</span><span class="Operator">(</span><span class="ID">evt</span><span class="Operator">.</span><span class="ID">GetItem</span><span class="Operator">(</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  71 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">AddTreeNodes</span><span class="Operator">(</span><span class="ID">evt</span><span class="Operator">.</span><span class="ID">GetItem</span><span class="Operator">(</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  72 </span></span>
<span class="line"><span class="LineNumber">  73 </span>    <span class="ResWord">def</span> <span class="ID">OnItemCollapsed</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">evt</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  74 </span>        <span class="ResWord">print</span> <span class="String">"OnItemCollapsed:"</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">GetItemText</span><span class="Operator">(</span><span class="ID">evt</span><span class="Operator">.</span><span class="ID">GetItem</span><span class="Operator">(</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  75 </span>        <span class="Comment"># And remove them when collapsed as we don't need them any longer</span></span>
<span class="line"><span class="LineNumber">  76 </span><span class="Comment"></span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">tree</span><span class="Operator">.</span><span class="ID">DeleteChildren</span><span class="Operator">(</span><span class="ID">evt</span><span class="Operator">.</span><span class="ID">GetItem</span><span class="Operator">(</span><span class="Operator">)</span><span class="Operator">)</span><span class="Comment">#折叠时删除结点</span></span>
<span class="line"><span class="LineNumber">  77 </span>    <span class="ResWord">def</span> <span class="ID">OnSelChanged</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">evt</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  78 </span>        <span class="ResWord">print</span> <span class="String">"OnSelChanged:   "</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">GetItemText</span><span class="Operator">(</span><span class="ID">evt</span><span class="Operator">.</span><span class="ID">GetItem</span><span class="Operator">(</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  79 </span>    <span class="ResWord">def</span> <span class="ID">OnActivated</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">evt</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  80 </span>        <span class="ResWord">print</span> <span class="String">"OnActivated:    "</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">GetItemText</span><span class="Operator">(</span><span class="ID">evt</span><span class="Operator">.</span><span class="ID">GetItem</span><span class="Operator">(</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  81 </span><span class="ID">app</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">PySimpleApp</span><span class="Operator">(</span><span class="ID">redirect</span><span class="Operator">=</span><span class="ID">True</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  82 </span><span class="ID">frame</span> <span class="Operator">=</span> <span class="ID">TestFrame</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  83 </span><span class="ID">frame</span><span class="Operator">.</span><span class="ID">Show</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  84 </span><span class="ID">app</span><span class="Operator">.</span><span class="ID">MainLoop</span><span class="Operator">(</span><span class="Operator">)</span><span class="Text"></span></span>
</pre>
</div>
<span id="line-782" class="anchor"></span><p class="line874">这个机制可以被扩展来从外部源读取数据以查看。这个机制除了可以被用来建造一个文件树外，我们会提及数据库中的数据的可能性，以便对文件的结构不感趣的你不用全面研究文件结构。 <span id="line-783" class="anchor"></span><span id="line-784" class="anchor"></span></p>
<p class="line867"><strong>控制可见性</strong> <span id="line-785" class="anchor"></span><span id="line-786" class="anchor"></span></p>
<p class="line862">有大量的方法使你能够管理那些项目是可见的。一个对象的不可见，可能是因为它没处在含有滚动条的框中的可见区域或是因为它处在折叠项中。你可以使用<tt>IsVisible(item)</tt>方法来确定项目是否可见，该方法在项目是可见时返回<tt>True</tt>，不可见返回<tt>False</tt>。你可以通过使用方法<tt>EnsureVisible(item)</tt>迫使指定的项变成可见的。如果需要的话，该方法将通过展开该项的父项（以及父项的父项，以此类推）来迫使指定项变成可见的，然后滚动该树，以使指定项处于控件的可见部分。如果你只需要滚动，可以使用<tt>ScrollTo(item)</tt>方法来完成。
<span id="line-787" class="anchor"></span><span id="line-788" class="anchor"></span></p>
<p class="line862">遍历树中的可见部分，首先要使用的方法是<tt>GetFirstVisibleItem()</tt>。该方法返回显示的可见部分中的最顶端的项目的<tt>wx.TreeItemId</tt>。然后通过使用<tt>GetNextVisible(item)</tt>方法来遍历，该方法的<tt>item</tt>参数来自<tt>GetFirstVisibleItem()</tt>和<tt>GetNextVisible()</tt>的返回值。如果移动的方向向上的话，使用方法<tt>GetPreviousVisible(item)</tt>。如果参数<tt>item</tt>不可见的话，返回值是一个无效的项。 <span id="line-789" class="anchor"></span><span id="line-790" class="anchor"></span></p>
<p class="line862">还有几个别的方法可用于项目的显示。树控件有一个属性，该属性用于设置缩进。可以通过方法<tt>GetIndent()</tt>和方法<tt>SetIndent(indent)</tt>来得到和设置该属性的当前值。其中<tt>indent</tt>参数是缩进的像素值（整数）。 <span id="line-791" class="anchor"></span><span id="line-792" class="anchor"></span></p>
<p class="line862">要得到关于指定点的树项目的信息，使用方法<tt>HitTest(point)</tt>，其中<tt>point</tt>是树控件中的相关位置的一个<tt>wx.Point</tt>。方法的返回值是一个(<tt>item, flags)</tt>元组，其中的<tt>item</tt>是相关位置的项的<tt>wx.TreeItemId</tt>或<tt>None</tt>值。如果指定位置没有项目，那么一个无效的项目将返回。<tt>flags</tt>部分是一个位掩码，它给出了相关的信息。表15.5包含了<tt>flags</tt>的一个完整列表。 <span id="line-793" class="anchor"></span><span id="line-794" class="anchor"></span></p>
<p class="line862">还有两个方法，它们让你可以处理屏幕上项目的实际的边界。方法<tt>GetBoundingRect(item,
textOnly=False)</tt>返回一个<tt>wx.Rect</tt>实例，该实例对应于屏幕上文本项的矩形边界区域。其中参数<tt>item</tt>是项目的<tt>wx.TreeItemId</tt>。如果参数<tt>textOnly</tt>为<tt>True</tt>，那么该矩形仅包括项目的显示文本所覆盖的区域。如果为<tt>False</tt>，那么该矩形也包括图像区域。在这两种情况中，矩形都包括从树控件的边缘到内嵌的显示项间的空白区域。如果<tt>item</tt>代表的项目当前是不可见的，那么两种方法都返回<tt>None</tt>。 <span id="line-795" class="anchor"></span><span id="line-796" class="anchor"></span></p>
<p class="line867"><strong>表15.5</strong> <span id="line-797" class="anchor"></span></p>
<div><table><tbody>
<tr>
<td><p class="line891"><tt>wx.TREE_HITTEST_ABOVE</tt> </p></td>
<td><p class="line862">该位置在树的客户区的上面，不是任何项目的一部分。 </p></td>
</tr>
<tr>
<td>
<span id="line-798" class="anchor"></span><p class="line891"><tt>wx.TREE_HITTEST_BELOW</tt> </p>
</td>
<td><p class="line862">该位置在树的客户区的下面，不是任何项目的一部分。 </p></td>
</tr>
<tr>
<td>
<span id="line-799" class="anchor"></span><p class="line891"><tt>wx.TREE_HITTEST_NOWhere</tt> </p>
</td>
<td><p class="line862">该位置处在树的客户区中，不是任何项目的一部分。 </p></td>
</tr>
<tr>
<td>
<span id="line-800" class="anchor"></span><p class="line891"><tt>wx.TREE_HITTEST_ONITEMBUTTON</tt> </p>
</td>
<td><p class="line862">该位置位于展开/折叠图标按钮上，是项目的一部分。 </p></td>
</tr>
<tr>
<td>
<span id="line-801" class="anchor"></span><p class="line891"><tt>wx.TREE_HITTEST_ONITEMICON</tt> </p>
</td>
<td><p class="line862">该位置位于项目的图像部分上。 </p></td>
</tr>
<tr>
<td>
<span id="line-802" class="anchor"></span><p class="line891"><tt>wx.TREE_HITTEST_ONITEMINDENT</tt> </p>
</td>
<td><p class="line862">该位置位于项目的显示文本的左边缩进区域中。 </p></td>
</tr>
<tr>
<td>
<span id="line-803" class="anchor"></span><p class="line891"><tt>wx.TREE_HITTEST_ONITEMLABEL</tt> </p>
</td>
<td><p class="line862">该位置位于项目的显示文本中。 </p></td>
</tr>
<tr>
<td>
<span id="line-804" class="anchor"></span><p class="line891"><tt>wx.TREE_HITTEST_ONITEMRIGHT</tt> </p>
</td>
<td><p class="line862">该位置是项目的显示文本的右边。 </p></td>
</tr>
<tr>
<td>
<span id="line-805" class="anchor"></span><p class="line891"><tt>wx.TREE_HITTEST_ONITEMSTATEICON</tt> </p>
</td>
<td><p class="line862">该位置是在项目的状态图标中。 </p></td>
</tr>
<tr>
<td>
<span id="line-806" class="anchor"></span><p class="line891"><tt>wx.TREE_HITTEST_TOLEFT</tt> </p>
</td>
<td><p class="line862">该位置在树的客户区的左面，不是任何项目的一部分。 </p></td>
</tr>
<tr>
<td>
<span id="line-807" class="anchor"></span><p class="line891"><tt>wx.TREE_HITTEST_TORIGHT</tt> </p>
</td>
<td><p class="line862">该位置在树的客户区的右面，不是任何项目的一部分。 </p></td>
</tr>
</tbody></table></div>
<span id="line-808" class="anchor"></span><span id="line-809" class="anchor"></span><span id="line-810" class="anchor"></span><p class="line867">
</p>
<h2 id="head-fdbfd503e411dd82ef3f20a0168d1dae8bf802ca">1.8. 使树控件可编辑</h2>
<span id="line-811" class="anchor"></span><p class="line862">树控件可以被设置为允许用户编辑树项目的显示文本。这通过在创建树控件时使用样式标记<tt>wx.TR_EDIT_LABELS</tt>来实现。使用了该样式标记后，树控件的行为就类似于可编辑的列表控件了。编辑一个树项目会给出一个文本控件来让用户编辑文本。按下<tt>esc</tt>则取消编辑。按下回车键或在文本控件外敲击将确认编辑。 <span id="line-812" class="anchor"></span><span id="line-813" class="anchor"></span></p>
<p class="line862">你可以在程序中使用<tt>EditLabel(item)</tt>方法来启动对特定项的编辑。参数<tt>item</tt>是你想要编辑的项的<tt>wx.TreeItemId</tt>。要终止编辑，可以使用方法<tt>EndEditLabel(cancelEdit)</tt>。由于一次只能有一个活动编辑项，所以这里不需要指定项目的<tt>ID</tt>。参数<tt>cancelEdit</tt>是一个布尔值。如果为<tt>True</tt>，取消编辑，如果为<tt>False</tt>，则不取消。如果因为某种原因，你需要访问当前所用的文本编辑控件，你可以调用方法<tt>GetEditControl()</tt>，该方法返回用于当前编辑的<tt>wx.TextCtrl</tt>实例，如果当前没有编辑，则返回<tt>None</tt>。当前该方法只工作于<tt>Windows</tt>系统下。
<span id="line-814" class="anchor"></span><span id="line-815" class="anchor"></span></p>
<p class="line862">当一个编辑会话开始时（通过用户选择或调用<tt>EditLabel()</tt>方法），<tt>wx.EVT_TREE_BEGIN_LABEL_EDIT</tt>类型的<tt>wx.TreeEvent</tt>事件被触发。如果使用<tt>Veto()</tt>方法否决了该事件的话，那么编辑将不会开始。当会话结束时（通过用户的敲击或调用<tt>EndEditLabel()</tt>方法），一个<tt>wx.EVT_TREE_END_LABEL_EDIT</tt>类型的事件被触发。这个事件也可以被否决，这样的话，编辑就被取消了，项目不会被改变。 <span id="line-816" class="anchor"></span><span id="line-817" class="anchor"></span></p>
<p class="line867">
</p>
<h2 id="head-abc34fdfc2cace683684bd937b30aff22876de95">1.9. 响应树控件的其它的用户事件</h2>
<span id="line-818" class="anchor"></span><p class="line862">在这一节，我们将讨论<tt>wx.TreeEvent</tt>类的属性。表15.6列出了这些属性。 <span id="line-819" class="anchor"></span><span id="line-820" class="anchor"></span></p>
<p class="line867"><strong>表15.6</strong>  <strong><tt>wx.TreeEvent</tt>的属性</strong> <span id="line-821" class="anchor"></span></p>
<div><table><tbody>
<tr>
<td><p class="line891"><tt>GetKeyCode()</tt> </p></td>
<td><p class="line862">返回所按键的整数按键码。只对<tt>wx.EVT_TREE_KEY_DOWN</tt>事件类型有效。如果任一修饰键（<tt>CTRL,SHIFT,and ALT</tt>之类的）也被按下，该属性不会告知你。 </p></td>
</tr>
<tr>
<td>
<span id="line-822" class="anchor"></span><p class="line891"><tt>GetItem()</tt> </p>
</td>
<td><p class="line862">返回与事件相关的项的<tt>wx.TreeItemId</tt>。 </p></td>
</tr>
<tr>
<td>
<span id="line-823" class="anchor"></span><p class="line891"><tt>GetKeyEvent()</tt> </p>
</td>
<td><p class="line862">只对<tt>wx.EVT_TREE_KEY_DOWN</tt>事件有效。返回<tt>wx.KeyEvent</tt>。该事件可以被用来告知你在该事件期间，是否有修饰键被按下。 </p></td>
</tr>
<tr>
<td>
<span id="line-824" class="anchor"></span><p class="line891"><tt>GetLabel()</tt> </p>
</td>
<td><p class="line862">返回项目的当前文本标签。只对<tt>wx.EVT_TREE_BEGIN_LABEL_EDIT</tt>和<tt>wx.EVT_TREE_END_LABEL_EDIT</tt>有效。 </p></td>
</tr>
<tr>
<td>
<span id="line-825" class="anchor"></span><p class="line891"><tt>GetPoint()</tt> </p>
</td>
<td><p class="line862">返回与该事件相关的鼠标位置的一个<tt>wx.Point</tt>。只对拖动事件有效。 </p></td>
</tr>
<tr>
<td>
<span id="line-826" class="anchor"></span><p class="line891"><tt>IsEditCancelled()</tt> </p>
</td>
<td><p class="line862">只对<tt>wx.EVT_TREE_END_LABEL_EDIT</tt>有效。如果用户通过取消来结束当前的编辑则返回<tt>True</tt>，否则返回<tt>False</tt>。 </p></td>
</tr>
<tr>
<td>
<span id="line-827" class="anchor"></span><p class="line891"><tt>SetToolTip(tooltip)</tt> </p>
</td>
<td><p class="line862">只对<tt>wx.EVT_TREE_ITEM_GETTOOLTIP</tt>事件有效。这使你能够得到关于项目的提示。该属性只作在<tt>Windows</tt>系统上。 </p></td>
</tr>
</tbody></table></div>
<span id="line-828" class="anchor"></span><span id="line-829" class="anchor"></span><span id="line-830" class="anchor"></span><p class="line862">表15.7列出了几个不适合在表15.6中列出的<tt>wx.TreeEvent</tt>的事件类型，它们有时也是用的。 <span id="line-831" class="anchor"></span><span id="line-832" class="anchor"></span></p>
<p class="line867"><strong>表15.7</strong>  <strong>树控件的另外的几个事件</strong> <span id="line-833" class="anchor"></span></p>
<div><table><tbody>
<tr>
<td><p class="line891"><tt>wx.EVT_TREE_BEGIN_DRAG</tt> </p></td>
<td><p class="line862">当用户通过按下鼠标左键来拖动树中的一个项目时，触发该事件。要让拖动时能够做些事情，该事件的处理函数必须显式地调用事件的<tt>Allow()</tt>方法。 </p></td>
</tr>
<tr>
<td>
<span id="line-834" class="anchor"></span><p class="line891"><tt>wx.EVT_TREE_BEGIN_RDRAG</tt> </p>
</td>
<td><p class="line862">当用户通过按下鼠标右键来拖动树中的一个项目时，触发该事件。要让拖动时能够做些事情，该事件的处理函数必须显式地调用事件的<tt>Allow()</tt>方法。 </p></td>
</tr>
<tr>
<td>
<span id="line-835" class="anchor"></span><p class="line891"><tt>wx.EVT_TREE_ITEM_ACTIVATED</tt> </p>
</td>
<td><p class="line862">当一个项目通过双击被激活时，触发该事件。 </p></td>
</tr>
<tr>
<td>
<span id="line-836" class="anchor"></span><p class="line891"><tt>wx.EVT_TREE_ITEM_GETTOOLTIP</tt> </p>
</td>
<td><p class="line862">当鼠标停留在树中的一个项目上时，触发该事件。该事件可用来为项目设置特定的提示。只需要在事件对像中简单地设置标签参数，其它的将由系统来完成。 </p></td>
</tr>
<tr>
<td>
<span id="line-837" class="anchor"></span><p class="line891"><tt>wx.EVT_TREE_KEY_DOWN</tt> </p>
</td>
<td><p class="line862">在树控件获得焦点的情况下，当一个键被按下时触发该事件。 </p></td>
</tr>
</tbody></table></div>
<span id="line-838" class="anchor"></span><span id="line-839" class="anchor"></span><span id="line-840" class="anchor"></span><p class="line874">上面这些就你需要了解的有关树控件的属性。下面，我们将通过一个有用的另一种形式的树控件来结束本章。 <span id="line-841" class="anchor"></span><span id="line-842" class="anchor"></span></p>
<p class="line867">
</p>
<h2 id="head-34e076b2ac08d7f7ea22a4b05ecdabe5e0838583">1.10. 使用树列表控件</h2>
<span id="line-843" class="anchor"></span><p class="line862">除了<tt>wx.TreeCtrl</tt>，<tt>wxPython</tt>也提供了<tt>wx.gizmos.TreeListCtrl</tt>，它是树控件和报告模式的列表控件的组合。除了本章中所讨论的<tt>wx.TreeCtrl</tt>的特性外，<tt>TreeListCtrl</tt>能够显示与每行相关的数据的附加列。图15.3显示了树列表控件的样子。 <span id="line-844" class="anchor"></span><span id="line-845" class="anchor"></span></p>
<p class="line867"><strong>图15.3</strong> <span id="line-846" class="anchor"></span><span id="line-847" class="anchor"></span></p>
<p class="line867"><img title="attachment:w15.3.gif" src="/moin/WxPythonInAction/ChapterFifteen?action=AttachFile&amp;do=get&amp;target=w15.3.gif" class="attachment"><span id="line-848" class="anchor"></span><span id="line-849" class="anchor"></span></p>
<p class="line874">例15.4是产生上图的代码 <span id="line-850" class="anchor"></span><span id="line-851" class="anchor"></span></p>
<p class="line867"><strong>例15.4</strong>  <strong>使用树列表控件</strong> <span id="line-852" class="anchor"></span><span id="line-853" class="anchor"></span></p>
<p class="line867"><span id="line-854" class="anchor"></span><span id="line-855" class="anchor"></span><span id="line-856" class="anchor"></span><span id="line-857" class="anchor"></span><span id="line-858" class="anchor"></span><span id="line-859" class="anchor"></span><span id="line-860" class="anchor"></span><span id="line-861" class="anchor"></span><span id="line-862" class="anchor"></span><span id="line-863" class="anchor"></span><span id="line-864" class="anchor"></span><span id="line-865" class="anchor"></span><span id="line-866" class="anchor"></span><span id="line-867" class="anchor"></span><span id="line-868" class="anchor"></span><span id="line-869" class="anchor"></span><span id="line-870" class="anchor"></span><span id="line-871" class="anchor"></span><span id="line-872" class="anchor"></span><span id="line-873" class="anchor"></span><span id="line-874" class="anchor"></span><span id="line-875" class="anchor"></span><span id="line-876" class="anchor"></span><span id="line-877" class="anchor"></span><span id="line-878" class="anchor"></span><span id="line-879" class="anchor"></span><span id="line-880" class="anchor"></span><span id="line-881" class="anchor"></span><span id="line-882" class="anchor"></span><span id="line-883" class="anchor"></span><span id="line-884" class="anchor"></span><span id="line-885" class="anchor"></span><span id="line-886" class="anchor"></span><span id="line-887" class="anchor"></span><span id="line-888" class="anchor"></span><span id="line-889" class="anchor"></span><span id="line-890" class="anchor"></span><span id="line-891" class="anchor"></span><span id="line-892" class="anchor"></span><span id="line-893" class="anchor"></span><span id="line-894" class="anchor"></span><span id="line-895" class="anchor"></span><span id="line-896" class="anchor"></span><span id="line-897" class="anchor"></span><span id="line-898" class="anchor"></span><span id="line-899" class="anchor"></span><span id="line-900" class="anchor"></span><span id="line-901" class="anchor"></span><span id="line-902" class="anchor"></span><span id="line-903" class="anchor"></span><span id="line-904" class="anchor"></span><span id="line-905" class="anchor"></span><span id="line-906" class="anchor"></span><span id="line-907" class="anchor"></span><span id="line-908" class="anchor"></span><span id="line-909" class="anchor"></span><span id="line-910" class="anchor"></span><span id="line-911" class="anchor"></span><span id="line-912" class="anchor"></span><span id="line-913" class="anchor"></span><span id="line-914" class="anchor"></span><span id="line-915" class="anchor"></span><span id="line-916" class="anchor"></span><span id="line-917" class="anchor"></span><span id="line-918" class="anchor"></span><span id="line-919" class="anchor"></span><span id="line-920" class="anchor"></span><span id="line-921" class="anchor"></span><span id="line-922" class="anchor"></span><span id="line-923" class="anchor"></span><span id="line-924" class="anchor"></span><span id="line-925" class="anchor"></span><span id="line-926" class="anchor"></span><span id="line-927" class="anchor"></span><span id="line-928" class="anchor"></span><span id="line-929" class="anchor"></span><span id="line-930" class="anchor"></span><span id="line-931" class="anchor"></span><span id="line-932" class="anchor"></span><span id="line-933" class="anchor"></span><span id="line-934" class="anchor"></span><span id="line-935" class="anchor"></span><span id="line-936" class="anchor"></span><span id="line-937" class="anchor"></span><span id="line-938" class="anchor"></span><span id="line-939" class="anchor"></span><span id="line-940" class="anchor"></span><span id="line-941" class="anchor"></span><span id="line-942" class="anchor"></span><span id="line-943" class="anchor"></span><span id="line-944" class="anchor"></span></p>
<div lang="en" dir="ltr" class="codearea">
<script type="text/javascript">
document.write('<a href="#" onclick="return togglenumber(\'CA-04df6179a799e8a8d172ec44522b281667a65e1c_008\', 1, 1);" \
class="codenumbers">切换行号显示<\/a>');
</script><a class="codenumbers" onclick="return togglenumber('CA-04df6179a799e8a8d172ec44522b281667a65e1c_008', 1, 1);" href="#">切换行号显示</a>
<pre lang="en" id="CA-04df6179a799e8a8d172ec44522b281667a65e1c_008" dir="ltr"><span class="line"><span class="LineNumber">   1 </span><span class="ResWord">import</span> <span class="ID">wx</span></span>
<span class="line"><span class="LineNumber">   2 </span><span class="ResWord">import</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">gizmos</span></span>
<span class="line"><span class="LineNumber">   3 </span><span class="ResWord">import</span> <span class="ID">data</span></span>
<span class="line"><span class="LineNumber">   4 </span><span class="ResWord">class</span> <span class="ID">TestFrame</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">Frame</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">   5 </span>    <span class="ResWord">def</span> <span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">   6 </span>        <span class="ID">wx</span><span class="Operator">.</span><span class="ID">Frame</span><span class="Operator">.</span><span class="ID">__init__</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">None</span><span class="Operator">,</span> <span class="ID">title</span><span class="Operator">=</span><span class="String">"TreeListCtrl"</span><span class="Operator">,</span> <span class="ID">size</span><span class="Operator">=</span><span class="Operator">(</span><span class="Number">400</span><span class="Operator">,</span><span class="Number">500</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">   7 </span>        <span class="Comment"># Create an image list</span></span>
<span class="line"><span class="LineNumber">   8 </span><span class="Comment"></span>        <span class="ID">il</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">ImageList</span><span class="Operator">(</span><span class="Number">16</span><span class="Operator">,</span><span class="Number">16</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">   9 </span>        <span class="Comment"># Get some standard images from the art provider and add them</span></span>
<span class="line"><span class="LineNumber">  10 </span><span class="Comment"></span>        <span class="Comment"># to the image list</span></span>
<span class="line"><span class="LineNumber">  11 </span><span class="Comment"></span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">fldridx</span> <span class="Operator">=</span> <span class="ID">il</span><span class="Operator">.</span><span class="ID">Add</span><span class="Operator">(</span></span>
<span class="line"><span class="LineNumber">  12 </span>            <span class="ID">wx</span><span class="Operator">.</span><span class="ID">ArtProvider</span><span class="Operator">.</span><span class="ID">GetBitmap</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">ART_FOLDER</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">ART_OTHER</span><span class="Operator">,</span> <span class="Operator">(</span><span class="Number">16</span><span class="Operator">,</span><span class="Number">16</span><span class="Operator">)</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  13 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">fldropenidx</span> <span class="Operator">=</span> <span class="ID">il</span><span class="Operator">.</span><span class="ID">Add</span><span class="Operator">(</span></span>
<span class="line"><span class="LineNumber">  14 </span>            <span class="ID">wx</span><span class="Operator">.</span><span class="ID">ArtProvider</span><span class="Operator">.</span><span class="ID">GetBitmap</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">ART_FILE_OPEN</span><span class="Operator">,</span>   <span class="ID">wx</span><span class="Operator">.</span><span class="ID">ART_OTHER</span><span class="Operator">,</span> <span class="Operator">(</span><span class="Number">16</span><span class="Operator">,</span><span class="Number">16</span><span class="Operator">)</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  15 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">fileidx</span> <span class="Operator">=</span> <span class="ID">il</span><span class="Operator">.</span><span class="ID">Add</span><span class="Operator">(</span></span>
<span class="line"><span class="LineNumber">  16 </span>            <span class="ID">wx</span><span class="Operator">.</span><span class="ID">ArtProvider</span><span class="Operator">.</span><span class="ID">GetBitmap</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">ART_NORMAL_FILE</span><span class="Operator">,</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">ART_OTHER</span><span class="Operator">,</span> <span class="Operator">(</span><span class="Number">16</span><span class="Operator">,</span><span class="Number">16</span><span class="Operator">)</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  17 </span></span>
<span class="line"><span class="LineNumber">  18 </span>        <span class="Comment"># Create the tree</span></span>
<span class="line"><span class="LineNumber">  19 </span><span class="Comment"></span><span class="Comment"># 创建树列表控件</span></span>
<span class="line"><span class="LineNumber">  20 </span><span class="Comment"></span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">tree</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">gizmos</span><span class="Operator">.</span><span class="ID">TreeListCtrl</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">style</span> <span class="Operator">=</span></span>
<span class="line"><span class="LineNumber">  21 </span>                                           <span class="ID">wx</span><span class="Operator">.</span><span class="ID">TR_DEFAULT_STYLE</span></span>
<span class="line"><span class="LineNumber">  22 </span>                                           <span class="Operator">|</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">TR_FULL_ROW_HIGHLIGHT</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  23 </span>        <span class="Comment"># Give it the image list</span></span>
<span class="line"><span class="LineNumber">  24 </span><span class="Comment"></span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">tree</span><span class="Operator">.</span><span class="ID">AssignImageList</span><span class="Operator">(</span><span class="ID">il</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  25 </span>        <span class="Comment"># create some columns</span></span>
<span class="line"><span class="LineNumber">  26 </span><span class="Comment"></span><span class="Comment">#创建一些列</span></span>
<span class="line"><span class="LineNumber">  27 </span><span class="Comment"></span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">tree</span><span class="Operator">.</span><span class="ID">AddColumn</span><span class="Operator">(</span><span class="String">"Class Name"</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  28 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">tree</span><span class="Operator">.</span><span class="ID">AddColumn</span><span class="Operator">(</span><span class="String">"Description"</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  29 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">tree</span><span class="Operator">.</span><span class="ID">SetMainColumn</span><span class="Operator">(</span><span class="Number">0</span><span class="Operator">)</span> <span class="Comment"># the one with the tree in it...</span></span>
<span class="line"><span class="LineNumber">  30 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">tree</span><span class="Operator">.</span><span class="ID">SetColumnWidth</span><span class="Operator">(</span><span class="Number">0</span><span class="Operator">,</span> <span class="Number">200</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  31 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">tree</span><span class="Operator">.</span><span class="ID">SetColumnWidth</span><span class="Operator">(</span><span class="Number">1</span><span class="Operator">,</span> <span class="Number">200</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  32 </span>        <span class="Comment"># Add a root node and assign it some images</span></span>
<span class="line"><span class="LineNumber">  33 </span><span class="Comment"></span>        <span class="ID">root</span> <span class="Operator">=</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">tree</span><span class="Operator">.</span><span class="ID">AddRoot</span><span class="Operator">(</span><span class="String">"wx.Object"</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  34 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">tree</span><span class="Operator">.</span><span class="ID">SetItemText</span><span class="Operator">(</span><span class="ID">root</span><span class="Operator">,</span> <span class="String">"A description of wx.Object"</span><span class="Operator">,</span> <span class="Number">1</span><span class="Operator">)</span><span class="Comment">#给列添加文本</span></span>
<span class="line"><span class="LineNumber">  35 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">tree</span><span class="Operator">.</span><span class="ID">SetItemImage</span><span class="Operator">(</span><span class="ID">root</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">fldridx</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">  36 </span>                               <span class="ID">wx</span><span class="Operator">.</span><span class="ID">TreeItemIcon_Normal</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  37 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">tree</span><span class="Operator">.</span><span class="ID">SetItemImage</span><span class="Operator">(</span><span class="ID">root</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">fldropenidx</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">  38 </span>                               <span class="ID">wx</span><span class="Operator">.</span><span class="ID">TreeItemIcon_Expanded</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  39 </span></span>
<span class="line"><span class="LineNumber">  40 </span>        <span class="Comment"># Add nodes from our data set</span></span>
<span class="line"><span class="LineNumber">  41 </span><span class="Comment"></span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">AddTreeNodes</span><span class="Operator">(</span><span class="ID">root</span><span class="Operator">,</span> <span class="ID">data</span><span class="Operator">.</span><span class="ID">tree</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  42 </span>        <span class="Comment"># Bind some interesting events</span></span>
<span class="line"><span class="LineNumber">  43 </span><span class="Comment"></span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Bind</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_TREE_ITEM_EXPANDED</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">OnItemExpanded</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">tree</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  44 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Bind</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_TREE_ITEM_COLLAPSED</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">OnItemCollapsed</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">tree</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  45 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Bind</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_TREE_SEL_CHANGED</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">OnSelChanged</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">tree</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  46 </span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">Bind</span><span class="Operator">(</span><span class="ID">wx</span><span class="Operator">.</span><span class="ID">EVT_TREE_ITEM_ACTIVATED</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">OnActivated</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">tree</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  47 </span>        <span class="Comment"># Expand the first level</span></span>
<span class="line"><span class="LineNumber">  48 </span><span class="Comment"></span>        <span class="ID">self</span><span class="Operator">.</span><span class="ID">tree</span><span class="Operator">.</span><span class="ID">Expand</span><span class="Operator">(</span><span class="ID">root</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  49 </span></span>
<span class="line"><span class="LineNumber">  50 </span>    <span class="ResWord">def</span> <span class="ID">AddTreeNodes</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">parentItem</span><span class="Operator">,</span> <span class="ID">items</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  51 </span>        <span class="String">"""</span></span>
<span class="line"><span class="LineNumber">  52 </span><span class="String">        Recursively traverses the data structure, adding tree nodes to</span></span>
<span class="line"><span class="LineNumber">  53 </span><span class="String">        match it.</span></span>
<span class="line"><span class="LineNumber">  54 </span><span class="String">        """</span></span>
<span class="line"><span class="LineNumber">  55 </span>        <span class="ResWord">for</span> <span class="ID">item</span> <span class="ResWord">in</span> <span class="ID">items</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  56 </span>            <span class="ResWord">if</span> <span class="ID">type</span><span class="Operator">(</span><span class="ID">item</span><span class="Operator">)</span> <span class="Operator">==</span> <span class="ID">str</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  57 </span>                <span class="ID">newItem</span> <span class="Operator">=</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">tree</span><span class="Operator">.</span><span class="ID">AppendItem</span><span class="Operator">(</span><span class="ID">parentItem</span><span class="Operator">,</span> <span class="ID">item</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  58 </span>                <span class="ID">self</span><span class="Operator">.</span><span class="ID">tree</span><span class="Operator">.</span><span class="ID">SetItemText</span><span class="Operator">(</span><span class="ID">newItem</span><span class="Operator">,</span> <span class="String">"A description of %s"</span> <span class="Operator">%</span> <span class="ID">item</span><span class="Operator">,</span> <span class="Number">1</span><span class="Operator">)</span><span class="Comment">#给列添加文本</span></span>
<span class="line"><span class="LineNumber">  59 </span>                <span class="ID">self</span><span class="Operator">.</span><span class="ID">tree</span><span class="Operator">.</span><span class="ID">SetItemImage</span><span class="Operator">(</span><span class="ID">newItem</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">fileidx</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">  60 </span>                                       <span class="ID">wx</span><span class="Operator">.</span><span class="ID">TreeItemIcon_Normal</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  61 </span>            <span class="ResWord">else</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  62 </span>                <span class="ID">newItem</span> <span class="Operator">=</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">tree</span><span class="Operator">.</span><span class="ID">AppendItem</span><span class="Operator">(</span><span class="ID">parentItem</span><span class="Operator">,</span> <span class="ID">item</span><span class="Operator">[</span><span class="Number">0</span><span class="Operator">]</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  63 </span>                <span class="ID">self</span><span class="Operator">.</span><span class="ID">tree</span><span class="Operator">.</span><span class="ID">SetItemText</span><span class="Operator">(</span><span class="ID">newItem</span><span class="Operator">,</span> <span class="String">"A description of %s"</span> <span class="Operator">%</span> <span class="ID">item</span><span class="Operator">[</span><span class="Number">0</span><span class="Operator">]</span><span class="Operator">,</span> <span class="Number">1</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  64 </span>                <span class="ID">self</span><span class="Operator">.</span><span class="ID">tree</span><span class="Operator">.</span><span class="ID">SetItemImage</span><span class="Operator">(</span><span class="ID">newItem</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">fldridx</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">  65 </span>                                       <span class="ID">wx</span><span class="Operator">.</span><span class="ID">TreeItemIcon_Normal</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  66 </span>                <span class="ID">self</span><span class="Operator">.</span><span class="ID">tree</span><span class="Operator">.</span><span class="ID">SetItemImage</span><span class="Operator">(</span><span class="ID">newItem</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">fldropenidx</span><span class="Operator">,</span></span>
<span class="line"><span class="LineNumber">  67 </span>                                       <span class="ID">wx</span><span class="Operator">.</span><span class="ID">TreeItemIcon_Expanded</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  68 </span></span>
<span class="line"><span class="LineNumber">  69 </span>                <span class="ID">self</span><span class="Operator">.</span><span class="ID">AddTreeNodes</span><span class="Operator">(</span><span class="ID">newItem</span><span class="Operator">,</span> <span class="ID">item</span><span class="Operator">[</span><span class="Number">1</span><span class="Operator">]</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  70 </span></span>
<span class="line"><span class="LineNumber">  71 </span>    <span class="ResWord">def</span> <span class="ID">GetItemText</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">item</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  72 </span>        <span class="ResWord">if</span> <span class="ID">item</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  73 </span>            <span class="ResWord">return</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">tree</span><span class="Operator">.</span><span class="ID">GetItemText</span><span class="Operator">(</span><span class="ID">item</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  74 </span>        <span class="ResWord">else</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  75 </span>            <span class="ResWord">return</span> <span class="String">""</span></span>
<span class="line"><span class="LineNumber">  76 </span></span>
<span class="line"><span class="LineNumber">  77 </span>    <span class="ResWord">def</span> <span class="ID">OnItemExpanded</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">evt</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  78 </span>        <span class="ResWord">print</span> <span class="String">"OnItemExpanded: "</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">GetItemText</span><span class="Operator">(</span><span class="ID">evt</span><span class="Operator">.</span><span class="ID">GetItem</span><span class="Operator">(</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  79 </span></span>
<span class="line"><span class="LineNumber">  80 </span>    <span class="ResWord">def</span> <span class="ID">OnItemCollapsed</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">evt</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  81 </span>        <span class="ResWord">print</span> <span class="String">"OnItemCollapsed:"</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">GetItemText</span><span class="Operator">(</span><span class="ID">evt</span><span class="Operator">.</span><span class="ID">GetItem</span><span class="Operator">(</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  82 </span>    <span class="ResWord">def</span> <span class="ID">OnSelChanged</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">evt</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  83 </span>        <span class="ResWord">print</span> <span class="String">"OnSelChanged:   "</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">GetItemText</span><span class="Operator">(</span><span class="ID">evt</span><span class="Operator">.</span><span class="ID">GetItem</span><span class="Operator">(</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  84 </span>    <span class="ResWord">def</span> <span class="ID">OnActivated</span><span class="Operator">(</span><span class="ID">self</span><span class="Operator">,</span> <span class="ID">evt</span><span class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber">  85 </span>        <span class="ResWord">print</span> <span class="String">"OnActivated:    "</span><span class="Operator">,</span> <span class="ID">self</span><span class="Operator">.</span><span class="ID">GetItemText</span><span class="Operator">(</span><span class="ID">evt</span><span class="Operator">.</span><span class="ID">GetItem</span><span class="Operator">(</span><span class="Operator">)</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  86 </span><span class="ID">app</span> <span class="Operator">=</span> <span class="ID">wx</span><span class="Operator">.</span><span class="ID">PySimpleApp</span><span class="Operator">(</span><span class="ID">redirect</span><span class="Operator">=</span><span class="ID">True</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  87 </span><span class="ID">frame</span> <span class="Operator">=</span> <span class="ID">TestFrame</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  88 </span><span class="ID">frame</span><span class="Operator">.</span><span class="ID">Show</span><span class="Operator">(</span><span class="Operator">)</span></span>
<span class="line"><span class="LineNumber">  89 </span><span class="ID">app</span><span class="Operator">.</span><span class="ID">MainLoop</span><span class="Operator">(</span><span class="Operator">)</span><span class="Text"></span></span>
</pre>
</div>
<span id="line-945" class="anchor"></span><p class="line874">树列表控件的很多方法和列表控件的相似，所以我们就再也没有列出并说明了。 <span id="line-946" class="anchor"></span><span id="line-947" class="anchor"></span></p>
<p class="line867">
</p>
<h2 id="head-0f9f54347594a8736b465a7457eaf66d7b582fc7">1.11. 本章小结</h2>
<span id="line-948" class="anchor"></span><p class="line862">1、树控件提供给你了一个如文件树或<tt>XML</tt>文档样的嵌套紧凑的外观。树控件是类<tt>wx.TreeCtrl</tt>的实例。有时，人你会想子类化<tt>wx.TreeCtrl</tt>，尤其是如果你需要实现自定义的排序的时候。 <span id="line-949" class="anchor"></span><span id="line-950" class="anchor"></span></p>
<p class="line862">2、要向树中添加项目，首先要用方法<tt>AddRoot(text, image=</tt>-1,
<tt>selImage=</tt>-1, <tt>data=None)</tt>。该函数的返回值是一个代表树的<tt>root</tt>项目的<tt>wx.TreeItemId</tt>。树控件使用<tt>wx.TreeItemId</tt>作为它自己的标识符类型，而非和其它控件一样使用整数的<tt>ID</tt>。一旦你得到了<tt>root</tt>项，你就可以使用方法<tt>AppendItem(parent, text, image=</tt>-1, <tt>selImage=</tt>-1,
<tt>data=None)</tt>来添加子项目，参数<tt>parent</tt>是父项目的<tt>ID</tt>。该方法返回新项目的<tt>wx.TreeItemId</tt>。另外还有一些用来将新的项目添加在不同位置的方法。方法<tt>Delete(item)</tt>从树中移除一个项目，方法<tt>DeleteChildren(item)</tt>移除指定项的所有子项目。 <span id="line-951" class="anchor"></span><span id="line-952" class="anchor"></span></p>
<p class="line862">3、树控件有一些用来改变树的显示外观的样式。一套是用来控制展开或折叠项目的按钮类型的。另一套是用来控制项目间的连接线的。第三套是用于控制树是单选还是多选的。你也可以使用样式通过隐藏树的实际的<tt>root</tt>，来模拟一个有着多个<tt>root</tt>项的树。 <span id="line-953" class="anchor"></span><span id="line-954" class="anchor"></span></p>
<p class="line862">4、默认情况下，树的项目通常是按照显示文本的字母顺序排序的。但是要使这能够实现，你必须给每项分配数据。实现这个的最容易的方法是使用<tt>SetItemPyData(item, obj)</tt>，它给项目分配一个任意的<tt>Python</tt>对象。如果你想使用该数据去写一个自定义的排序函数，你必须继承<tt>wx.TreeCtrl</tt>类并覆盖方法<tt>OnCompareItems(item1,
item2)</tt>，其中的参数<tt>item1</tt>和<tt>item2</tt>是要比较的项的<tt>ID</tt>。 <span id="line-955" class="anchor"></span><span id="line-956" class="anchor"></span></p>
<p class="line862">5、树控件使用一个图像列表来管理图像，类似于列表控件管理图像的方法。你可以使用<tt>SetImageList(imageList)</tt>或<tt>AssignImageList(imageList)</tt>来分配一个图像列表给树控件。然后，当新的项目被添加到列表时，你可以将它们与图像列表中的特定的索引联系起来。 <span id="line-957" class="anchor"></span><span id="line-958" class="anchor"></span></p>
<p class="line862">6、没有特定的函数可以让你得到一个父项的子项目列表。替而代之的是，你需要去遍历子项目列表，这通过使用方法<tt>GetFirstChild(item)</tt>作为开始。 <span id="line-959" class="anchor"></span><span id="line-960" class="anchor"></span></p>
<p class="line862">7、你可以使用方法<tt>SelectItem(item,
select=True)</tt>来管理树的项目的选择。在一个多选树中，你可以使用<tt>ToggleItemSelection(item)</tt>来改变给定项的状态。你可以使用<tt>IsSelected(item)</tt>来查询一个项目的状态。你也可以使用<tt>Expand(item)</tt>或<tt>Collapse(item)</tt>展开或折叠一个项，或使用<tt>Toggle(item)</tt>来切换它的状态。 <span id="line-961" class="anchor"></span><span id="line-962" class="anchor"></span></p>
<p class="line862">8、样式<tt>wx.TR_EDIT_LABELS</tt>使得树控件可为用户所编辑。一个可编辑的列表中，用户可以选择一个项，并键入一个新的标签。按下<tt>esc</tt>来取消编辑而不对项目作任何改变。你也可以通过 <tt>wx.EVT_TREE_END_LABEL_EDIT </tt>事件来否决编辑。类<tt>wx.TreeEvent</tt>提供了允许访问当前被处理的项目的显示文本的属性。 <span id="line-963" class="anchor"></span><span id="bottom" class="anchor"></span></p>
</div>
</div>
</td>
                    </tr></tbody></table>
</div>
        
        
        
        <td id="portal-column-two">
            <div class="visualPadding">
                <!-- The sticky notes -->
                 
            </div>
        </td>
        
        
        
        <div class="visualClear" id="clear-space-before-footer">
            <!-- -->
        </div>
        <hr class="netscape4">
<div id="portal-footer">
            <p> 中国Zope/Plone用户组 - 站长  ： <a target="_self" href="http://czug.org/blog/panjy"> 潘俊勇 </a>、
             <a target="_self" href="http://czug.org/blog/zhangbingkai"> 张炳凯 </a>
            </p>
        </div>
        <div id="portal-colophon">

            <p>
            本站由<a target="_blank" href="http://zopen.cn" alt="润普公司 内容管理 文档管理 知识管理 项目管理 Zope Plone">
                   润普公司</a>资助，
            采用 <a href="http://opensource.everydo.com/cms/">易度CMS </a> 构建。</p>

            <p class="discreet">
            广而告之：润普公司 <a href="http://everydo.com">易度云办公平台</a>，包括<a href="http://edodocs.com"> 易度文档管理系统 </a>，<a href="http://everydo.com/themes/czug.org/pm.everydo.com%0A">易度项目管理系统 </a> , <a href="http://everydo.com/tour/dept.rst"> 易度部门管理 </a> ，均采用Zope 3/BFG技术开发。
            <br><a target="_blank" href="http://www.miibeian.gov.cn/">沪ICP备05008050</a>
            </p>
            </div>
        
        
        <script type="text/javascript">
        var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
        document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
        </script><script type="text/javascript">
        try {
        var pageTracker = _gat._getTracker("UA-13170837-4");
        pageTracker._trackPageview();
        } catch(err) {}</script>
</body>
</html>
